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 />

is equal to<br />

==<br />

if [ "$a" = "$b" ]<br />

is equal to<br />

if [ "$a" == "$b" ]<br />

This is a synonym for =.<br />

[[ $a == z* ]] # true if $a starts with an "z" (pattern matching)<br />

[[ $a == "z*" ]] # true if $a is equal to z*<br />

[ $a == z* ] # file globbing and word splitting take place<br />

[ "$a" == "z*" ] # true if $a is equal to z*<br />

!=<br />

# Thanks, S.C.<br />

is not equal to<br />

if [ "$a" != "$b" ]<br />

<<br />

This operator uses pattern matching within a [[ ... ]] construct.<br />

is less than, in ASCII alphabetical order<br />

if [[ "$a" < "$b" ]]<br />

if [ "$a" \< "$b" ]<br />

><br />

Note that the "" needs to be escaped within a [ ] construct.<br />

−z<br />

−n<br />

See Example 26−6 for an application of this comparison operator.<br />

string is "null", that is, has zero length<br />

string is not "null".<br />

The −n test absolutely requires that the string be quoted within the test brackets.<br />

Using an unquoted string with ! −z, or even just the unquoted string alone within<br />

test brackets (see Example 7−6) normally works, however, this is an unsafe practice.<br />

Always quote a tested string. [18]<br />

Chapter 7. Tests 50

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

Saved successfully!

Ooh no, something went wrong!