27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

\<br />

/<br />

`<br />

:<br />

let "t2 = ((a = 9, 15 / 3))" # Set "a" and calculate "t2".<br />

escape. [backslash] \X "escapes" the character X. This has the effect of "quoting" X, equivalent to 'X'.<br />

The \ may be used to quote " and ', so they are expressed literally.<br />

See Chapter 5 for an in−depth explanation of escaped characters.<br />

Filename path separator. [forward slash] Separates the components of a filename (as in<br />

/home/bozo/projects/Makefile).<br />

This is also the division arithmetic operator.<br />

command substitution. [backticks] `command` makes available the output of command for setting a<br />

variable. This is also known as backticks or backquotes.<br />

null command. [colon] This is the shell equivalent of a "NOP" (no op, a do−nothing operation). It<br />

may be considered a synonym for the shell builtin true. The ":" command is a itself a Bash builtin,<br />

and its exit status is "true" (0).<br />

:<br />

echo $? # 0<br />

Endless loop:<br />

while :<br />

do<br />

operation−1<br />

operation−2<br />

...<br />

operation−n<br />

done<br />

# Same as:<br />

# while true<br />

# do<br />

# ...<br />

# done<br />

Placeholder in if/then test:<br />

if condition<br />

then : # Do nothing and branch ahead<br />

else<br />

take−some−action<br />

fi<br />

Provide a placeholder where a binary operation is expected, see Example 8−2 and default parameters.<br />

: ${username=`whoami`}<br />

# ${username=`whoami`} without the leading : gives an error<br />

# unless "username" is a command or builtin...<br />

Provide a placeholder where a command is expected in a here document. See Example 17−9.<br />

Chapter 3. Special Characters 9

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

Saved successfully!

Ooh no, something went wrong!