Quoting command arguments

The characters

   ;  &  ( )  |  ^  <  >  ~  %  { }
   $  #   '  "  \  @@  *  ?  [ ]  -  ! 
   Newline 
   Space   
   Tab	   

are all shell metacharacters - they represent something other than the character or symbol that they are. You must therefore quote any command argument or regular expression containing one or more of these, so that it is passed to the command unchanged.

Always quote the command argument or regular expression if you want to prevent the shell from interpreting the special characters before passing it to the command.

Examples

To remove the special meaning from a single metacharacter:

   rcp ubik:/usr/home/roger/recipe.ps .;\\<Return>
   lpr -Pps3 #6m recipe.ps

This prevents the shell from expanding the newline character generated by pressing the <Return> key. You can then continue entering the command on the next line.

To prevent the shell from expanding special characters but allow command substitution:

   echo 'My working directory is `pwd`'
   My working directory is`pwd`
   echo "My working directory is `pwd`"
   My working directory is /home/jane/docs

When enclosed within single quotes the characters `pwd` are treated literally as part of the string to be echoed. Placed within double quotes, the command within the backquotes is executed and its output substituted in its place.