Quoting

Unix has 4 kinds of quotes

Single Quotes

Removes the special meaning of all characters between two single quotes. Can include all characters execpt a single quote.

Double Quotes

Removes the special meaning of all characters between two double quotes execpt dollar sign ($), backslash (\) and the back quote (`).

Backslash

Remove the special meaning of the ONE character after the backslash. Any character after the backslash is taken literally.

One execption is when the backslash is the last character on a line. This will continue the line on the next without inserting a newline character. The backslash and newline are removed and the lines are treated as one line.

Backslash inside Double Quotes

The backslash can be used inside double quotes to remove the special meaning of the dollar sign, backslash, and the back quote as well as the double quote itself. It can also be used for line continuation if it is the last character on the line. Otherwise, if a backslash appears inside double quotes, it will be left as is.

Command Substitution

This is quite different than the previous quoting. Here we run a command and then substitute the resulting output back onto the commandline. This can be done with backquotes or $(...) construct.

Back Quotes

Anything in the back quotes is executed as if it was typed at a command prompt, then the back quote expression is replaced with the output of the command.

The $(...) Construct

Most shells also allow $(...) to be used instead of backquotes. This form is the prefered method to use. It is easier to read and allows for easy nesting.

The expr command

The expr command is used in older shells that cannot do integer expressions. Therefore, you might see it in some older scripts. We will not cover it in this course.