Back

Conference Topic:

Why does UNIX confuse me by making me remember the different uses of single quotes, double quotes, and backwards quotes?

Could you comment on why these three mechanisms were introduced, where are they used, and perhaps on how would you get the same results in a different way?

Response:

Theresa L. Ford on 03-05-2004

Quotes are used by the shell interpreter to parse command lines. The precise syntax and peculiarities of quoting changes from shell to shell, despite sometimes seeming similar. This is because each shell processes command lines slightly differently.

Using white space, quoting, and metacharacters, the shells can:
Process white space.
Parse commands from arguments.
Process escaped characters.
Process metacharacters.
Substitute (variables, aliases, and other things).
Execute commands.
Make data streams.

Some equivalencies:
echo `pwd`
echo $(pwd)

cat fil*
cat file1 file2 file3

echo "T's home: $HOME"
echo "T"\'"s home: $HOME"
echo 'T'\''s home: /home/morph'
echo 'T'\'"s home: $HOME"
echo 'T'"'s home: "$HOME
echo "T's home: `cd;pwd`"
echo "T's home: "`cd;pwd`
echo "T's home: "$(cd;pwd)

And so on. The shell is a programming environment, not just a place to type commands. Quoting allows programs to be written and interpreted correctly.

http://www.mpi-sb.mpg.de/~uwe/lehre/unixffb/quoting-guide.html

Back