#!/bin/sh
test -n "$RANDOM" || echo OK
test.sh:2:10: warning: In POSIX sh, RANDOM is undefined. [SC2039]
No warning, because test -n (or test -z) guards against the possibility of $RANDOM being empty, thus making it possible to write portable scripts that work safely in POSIX sh'.
Well it is not assigned in your example so the warning is fully legit.
I argue that an exception could be made for test -n and test -z on such variables. In some scripts, you are trying to test if the user has set an optional variable outside the script.
not sure about -z/-n usage, but allowing +set seems reasonable.
if [ "${RANDOM+set}" = "set" ]; then
...
fi
alternatively, if you're writing bash code, why not use a bash shebang to begin with ?
Most helpful comment
I argue that an exception could be made for
test -nandtest -zon such variables. In some scripts, you are trying to test if the user has set an optional variable outside the script.