Quotes

Shell recognizes three types of quotes, used when you have a string with whitespace in it that needs to be treated as a single argument:
  1. Double quotes (") - used when you want the shell to expand the string inside. For instance, type:
    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"
  2. Single quotes (') - used when you do NOT want the shell to expand the string inside. For instance, type:
    echo 'My Home is $HOME'
    Notice what happens.
  3. Back quotes (`) - used to execute the command and replace it with the output, which may have whitespace in it. For instance:
    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?

Escaping Characters