Previous | Next

dollar-X

echo -n "Would you like to play a game? "
read x

x=`echo $x | sed 's/[^-a-z0-9]//g'`

if [ -f /usr/games/$x ] ; then
	tput clear
	exec /usr/games/$x
else
	echo How about a nice game of
	ls /usr/games
	exec cat <<QUOTE
A strange game.
The only winning move is
not to play.
QUOTE
fi
exit 0
What's all this dollar-X stuff?

Obviously nothing to do with money.

But look how it's used with /usr/games -- we can speculate that it's the filename it's trying to run as a game.

It's just a noun.

It can change, so it's called a variable.

Lots of languages use dollar signs to indicate variables. (Shells, Perl, PHP.)