echo "My Home is $HOME"
Notice what happens. You could also do this:
echo My Home "is $HOME"
How many arguments are being passed to echo in each of the previous examples? In the case of echo, it doesn't really matter since echo prints all of its arguments to the screen, but for some things it does matter. For instance, which of these are correct?
VAR=My Home "is $HOME"
VAR="My Home is $HOME"
echo 'My Home is $HOME'
Notice what happens.
h=`pwd`
If you run it while in the /tmp directory, the shell executes
the pwd command and uses the output to actually run this:
h=/tmp
If you run
echo $h
it will print /tmp. You could also cd somewhere else, then type
cd $h
to return. When else would this be useful?
For instance:
echo "My \$HOME is $HOME"
grep '\-?' *
The single quotes protect the string from the shell, and the \ before the -
tells grep not to process it as a flag, but the actually search for the string
-?.
d="Today is `date`"
cd `echo $HOME`
echo "\$HOME is $HOME"