freddy36 / check_mk_extensions

Extensions for check_mk
GNU General Public License v3.0
11 stars 10 forks source link

awk count strings from 1 not 0. Couting from 0 broke mawk implementation #4

Closed theundefined closed 7 years ago

theundefined commented 7 years ago
undefine@undefine-ThinkPad-T430s:~$ echo x |mawk '{print substr("012345",0,4)}'
012
undefine@undefine-ThinkPad-T430s:~$ echo x |gawk '{print substr("012345",0,4)}'
0123
freddy36 commented 7 years ago

This was changed to 0 in 1f788d622ac84ad90d340bca0794c2e664706fec by @gurubert @gurubert which awk flavor/version are you using which expects 0 here? 1 seems to be the correct in my opinion.

gurubert commented 7 years ago

There is a difference between mawk and gawk. At the time I wrote the patch we had gawk installed. I think you should explicitely call mawk which starts counting at 1.

theundefined commented 7 years ago

I think correct solution is counting from 1 ;) It works both on mawk and gawk. And probably any other awk implementation.