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.

# AND LIST executes on true, OR LIST on false.<br />

exit 0<br />

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

If the first command in an "or list" returns true, it will execute.<br />

The exit status of an and list or an or list is the exit status of the last command executed.<br />

Clever combinations of "and" and "or" lists are possible, but the logic may easily become convoluted and<br />

require extensive debugging.<br />

false && true || echo false<br />

# false<br />

# Same result as<br />

( false && true ) || echo false # false<br />

# But *not*<br />

false && ( true || echo false ) # (nothing echoed)<br />

# Note left−to−right grouping and evaluation of statements,<br />

# since the logic operators "&&" and "||" have equal precedence.<br />

# It's best to avoid such complexities, unless you know what you're doing.<br />

# Thanks, S.C.<br />

See Example A−8 and Example 7−4 for illustrations of using an and / or list to test variables.<br />

Chapter 25. List Constructs 291

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

Saved successfully!

Ooh no, something went wrong!