24.07.2018 Views

Bash-Beginners-Guide

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Bash</strong> <strong>Guide</strong> for <strong>Beginners</strong><br />

franky ~> echo "`date`"<br />

Sun Apr 20 11:22:06 CEST 2003<br />

franky ~> echo "I'd say: \"Go for it!\""<br />

I'd say: "Go for it!"<br />

franky ~> echo "\"<br />

More input>"<br />

franky ~> echo "\\"<br />

\<br />

3.3.5. ANSI-C quoting<br />

Words in the form "$'STRING'" are treated in a special way. The word expands to a string, with<br />

backslash-escaped characters replaced as specified by the ANSI-C standard. Backslash escape sequences can<br />

be found in the <strong>Bash</strong> documentation.<br />

3.3.6. Locales<br />

A double-quoted string preceded by a dollar sign will cause the string to be translated according to the current<br />

locale. If the current locale is "C" or "POSIX", the dollar sign is ignored. If the string is translated and<br />

replaced, the replacement is double-quoted.<br />

3.4. Shell expansion<br />

3.4.1. General<br />

After the command has been split into tokens (see Section 1.4.1.1), these tokens or words are expanded or<br />

resolved. There are eight kinds of expansion performed, which we will discuss in the next sections, in the<br />

order that they are expanded.<br />

After all expansions, quote removal is performed.<br />

3.4.2. Brace expansion<br />

Brace expansion is a mechanism by which arbitrary strings may be generated. Patterns to be brace-expanded<br />

take the form of an optional PREAMBLE, followed by a series of comma-separated strings between a pair of<br />

braces, followed by an optional POSTSCRIPT. The preamble is prefixed to each string contained within the<br />

braces, and the postscript is then appended to each resulting string, expanding left to right.<br />

Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is<br />

preserved:<br />

franky ~> echo sp{el,il,al}l<br />

spell spill spall<br />

Brace expansion is performed before any other expansions, and any characters special to other expansions are<br />

preserved in the result. It is strictly textual. <strong>Bash</strong> does not apply any syntactic interpretation to the context of<br />

the expansion or the text between the braces. To avoid conflicts with parameter expansion, the string "${" is<br />

not considered eligible for brace expansion.<br />

Chapter 3. The <strong>Bash</strong> environment 46

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!