Up Next Previous

Lexical structure

The shell splits input lines into words at blanks and tabs. The special characters `&', `|', `;', `<', `>', `(', and `)' and the doubled characters `&&', `||', `<<' and `>>' are always separate words, whether or not they are surrounded by whitespace.

When the shell's input is not a terminal, the character `#' is taken to begin a comment. Each `#' and the rest of the input line on which it appears is discarded before further parsing.

A special character (including a blank or tab) may be prevented from having its special meaning, and possibly made part of another word, by preceding it with a backslash (`\') or enclosing it in single (`''), double (`"') or backward (``') quotes. When not otherwise quoted a newline preceded by a `\' is equivalent to a blank, but inside quotes this sequence results in a newline.

Furthermore, all Substitutions (see below) except History substitution can be prevented by enclosing the strings (or parts of strings) in which they appear with single quotes or by quoting the crucial character(s) (e.g. `$' or ``' for Variable substitution or Command substitution respectively) with `\'. History substitutions are quoted in the same way by backslashes but not by single quotes. Strings quoted with double or backward quotes undergo Variable substitution and Command substitution, but other substitutions are prevented.

Text inside single or double quotes becomes a single word (or part of one). Metacharacters in these strings, including blanks and tabs, do not form separate words. Only in one special case (see Command substitution below) can a double-quoted string yield parts of more than one word; single-quoted strings never do. Backward quotes are special: they signal Command substitution (q.v.), which may result in more than one word.

Quoting complex strings, particularly strings which themselves contain quoting characters, can be confusing. Remember that quotes need not be used as they are in human writing! It may be easier to quote not an entire string, but only those parts of the string which need quoting, using different types of quoting to do so if appropriate.

The backslash_quote shell variable (q.v.) can be set to make backslashes always quote `\', `'', and `"'. (+) This may make complex quoting tasks easier, but it can cause syntax errors in csh(1) scripts.

Up Next Previous