Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 573 Bytes

SC3028.md

File metadata and controls

25 lines (16 loc) · 573 Bytes

Pattern: Use of undefined variable

Issue: -

Description

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)"

Further Reading