The following script works fine in one of my machines, printing 1 then 2:
#!/bin/sh
echo "1"
shift
echo "2"
On another machine, however, it produces the following output:
1
./script.sh: 4: shift: can't shift that many
man shift does not help (No manual entry for shift).
What is that error, why is it happening, and how can I fix it?
let $# && shiftaka(( $# )) && shiftis another form of conditionally doing a shift. If i understand it correctly, the double parenthesis (or: two parentheses, or: two round brackets) are the same as the commandletwhich allows for arithmetic evaluation. Andlet 0(or:(( 0 ))) evaluates to a non-zero exit. – immeëmosol May 25 '22 at 10:16test $(( $# )) && shiftas((&letseem not to be in the standard. perhaps relevant: https://github.com/koalaman/shellcheck/wiki/SC2219 . – immeëmosol May 25 '22 at 11:47