And errors out expectedly using dash or ash, very nice POSIX Sh compliant shells:

$ ./foo.sh
./foo.sh: line 5: [: bar: integer expression expected

So the lessons here are twofold:

  • Always use shellcheck to check your shell code
  • Never use Bash or rely on Bash(isms). Always prefer POSIX Sh

⤋ Read More

@prologic@twtxt.net Yeah, that is part of the problem. Bash is so dominant on Linux, it’s hard to avoid. When I use #!/bin/sh, it still gets me a Bash that does NOT enter strict POSIX mode. 🫤 The script below uses Bashisms and requests #!/bin/sh but still runs happily …

#!/bin/sh

foo=1

if [[ "$foo" == 1 ]]
then
    echo match
fi

⤋ Read More

@prologic@twtxt.net Yeah, that is part of the problem. Bash is so dominant on Linux, it’s hard to avoid. When I use #!/bin/sh, it still gets me a Bash that does NOT enter strict POSIX mode. 🫤 The script below uses Bashisms and requests #!/bin/sh but still runs happily …

#!/bin/sh

foo=1

if

⤋ Read More

Participate

Login to join in on this yarn.