$title = "Quoting command arguments"; $area = "Unix Support"; $metadata = unix, command, argument, quote, quoting, metacharacter""; $pfloc = ""; require '/usr/local/wwwdocs/ucs/fragments/header.phtml'; require '/usr/local/wwwdocs/ucs/fragments/header-bc.phtml'; ?>
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.
\\ prevent the shell from expanding any single special character.
All special characters enclosed in single quotes ('') except ! are not expanded by the shell
All special characters enclosed in double quotes (" ") except $, ` and ! are not expanded by the shell
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.
require '/usr/local/wwwdocs/ucs/fragments/footer.phtml'; ?>