Excerts from the man pages for bash: These excepts are intended to give you some of the basic info on how to do quoting in this shell and on the order of expansion of various things in your scripts. Use the following for more complete information: man bash metacharacter A character that, when unquoted, separates words. One of the following: | & ; ( ) < > space tab Quoting Quoting is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to disable special treatment for special characters, to pre- vent reserved words from being recognized as such, and to prevent parameter expansion. Each of the metacharacters listed above under DEFINITIONS has special meaning to the shell and must be quoted if they are to represent themselves. There are three quoting mechanisms: the escape character, single quotes, and dou- ble quotes. A non-quoted backslash (\) is the escape character. It preserves the literal value of the next character that follows, with the exception of . If a \ pair appears, and the backslash is not quoted, the \ is treated as a line continuation (that is, it is effectively ignored). Enclosing characters in single quotes preserves the lit- eral value of each character within the quotes. A single quote may not occur between single quotes, even when pre- ceded by a backslash. Enclosing characters in double quotes preserves the lit- eral value of all characters within the quotes, with the exception of $, `, and \. The characters $ and ` retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or . A double quote may be quoted within double quotes by preced- ing it with a backslash. The special parameters * and @ have special meaning when in double quotes (see PARAMETERS below). Expansion Expansion is performed on the command line after it has been split into words. There are seven kinds of expansion performed: brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion. The order of expansions is: brace expansion, tilde expan- sion, parameter, variable, command, and arithmetic substi- tution (done in a left-to-right fashion), word splitting, and pathname expansion. See "man bash" for brace expansion. Tilde Expansion If a word begins with a tilde character (`~'), all of the characters preceding the first slash (or all characters, if there is no slash) are treated as a possible login name. If this login name is the null string, the tilde is replaced with the value of the parameter HOME. If HOME is unset, the home directory of the user executing the shell is substituted instead. Parameter Expansion The `$' character introduces parameter expansion, command substitution, or arithmetic expansion. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name. ${parameter} The value of parameter is substituted. The braces are required when parameter is a positional parame- ter with more than one digit, or when parameter is followed by a character which is not to be inter- preted as part of its name. Command Substitution Command substitution allows the output of a command to replace the command name. There are two forms: $(command) or `command` Bash performs the expansion by executing command and replacing the command substitution with the standard out- put of the command, with any trailing newlines deleted. If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results. Arithmetic Expansion Arithmetic expansion allows the evaluation of an arith- metic expression and the substitution of the result. There are two formats for arithmetic expansion: $[expression] $((expression)) See "man bash" for more information. Word Splitting The shell scans the results of parameter expansion, com- mand substitution, and arithmetic expansion that did not occur within double quotes for word splitting. The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words on these characters. If the value of IFS is exactly , the default, then any sequence of IFS characters serves to delimit words. Pathname Expansion After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of pathnames matching the pattern. The special pattern characters have the following meanings: * Matches any string, including the null string. ? Matches any single character. [...] Matches any one of the enclosed characters. A pair of characters separated by a minus sign denotes a range; any character lexically between those two characters, inclusive, is matched. If the first character following the [ is a ! or a ^ then any character not enclosed is matched. A - or ] may be matched by including it as the first or last char- acter in the set.