Pattern: Use of undefined variable
Issue: -
The variable you are attempting to use is a special variable in bash or ksh. To get the same information from dash
or POSIX sh
, use an external command instead.
Example of incorrect code:
#!/bin/sh
echo "$HOSTNAME $UID $RANDOM"
Example of correct code:
#!/bin/sh
echo "$(hostname) $(id -u) $(awk 'BEGIN { srand(); print int(rand()*32768) }' /dev/null)"