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.

(cd /source/directory && tar cf − . ) | \<br />

(cd /dest/directory && tar xpvf −)<br />

# Repeating Alan Cox's directory tree copy command,<br />

# but split into two lines for increased legibility.<br />

# As an alternative:<br />

tar cf − −C /source/directory . |<br />

tar xpvf − −C /dest/directory<br />

# See note below.<br />

# (Thanks, Stephane Chazelas.)<br />

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

If a script line ends with a |, a pipe character, then a \, an escape, is not strictly necessary. It is, however,<br />

good programming practice to always escape the end of a line of code that continues to the following<br />

line.<br />

echo "foo<br />

bar"<br />

#foo<br />

#bar<br />

echo<br />

echo 'foo<br />

bar' # No difference yet.<br />

#foo<br />

#bar<br />

echo<br />

echo foo\<br />

bar # Newline escaped.<br />

#foobar<br />

echo<br />

echo "foo\<br />

bar" # Same here, as \ still interpreted as escape within weak quotes.<br />

#foobar<br />

echo<br />

echo 'foo\<br />

bar' # Escape character \ taken literally because of strong quoting.<br />

#foor\<br />

#bar<br />

# Examples suggested by Stephane Chazelas.<br />

Chapter 5. Quoting 37

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

Saved successfully!

Ooh no, something went wrong!