2 # the test/[ code is tested elsewhere, and the [[...]] just uses the same
3 # code. this tests the special features of [[...]]
7 # this one is straight out of the ksh88 book
8 [[ foo > bar && $PWD -ef . ]]
11 # [[ x ]] is equivalent to [[ -n x ]]
15 # [[ ! x ]] is equivalent to [[ ! -n x ]]
19 # ! binds tighter than test/[ -- it binds to a term, not an expression
23 # parenthesized terms didn't work right until post-2.04
36 # unset variables don't need to be quoted
43 # the ==/= and != operators do pattern matching
44 [[ $TDIR == /usr/homes/* ]]
47 # ...but you can quote any part of the pattern to have it matched as a string
48 [[ $TDIR == /usr/homes/\* ]]
51 [[ $TDIR == '/usr/homes/*' ]]
54 # if the first part of && fails, the second is not executed
55 [[ -n $UNSET && $UNSET == foo ]]
58 [[ -z $UNSET && $UNSET == foo ]]
61 # if the first part of || succeeds, the second is not executed
62 [[ -z $UNSET || -d $PWD ]]
65 # if the rhs were executed, it would be an error
66 [[ -n $TDIR || $HOME -ef ${H*} ]]
69 [[ -n $TDIR && -z $UNSET || $HOME -ef ${H*} ]]
72 # && has a higher parsing precedence than ||
73 [[ -n $TDIR && -n $UNSET || $TDIR -ef . ]]
76 # ...but expressions in parentheses may be used to override precedence rules
77 [[ -n $TDIR || -n $UNSET && $PWD -ef xyz ]]
80 [[ ( -n $TDIR || -n $UNSET ) && $PWD -ef xyz ]]
83 # some arithmetic tests for completeness -- see what happens with missing
84 # operands, bad expressions, makes sure arguments are evaluated as
85 # arithmetic expressions, etc.
114 # more pattern matching tests
116 [[ $filename == *.c ]]
121 [[ $filename == *.c ]]
124 # the extended globbing features may be used when matching patterns
129 [[ $arg == -+([0-9]) ]]
134 [[ $arg == -+([0-9]) ]]
138 [[ $arg == ++([0-9]) ]]
141 # make sure the null string is never matched if the string is not null
145 if [[ $STR = $PAT ]]; then
149 # but that if the string is null, a null pattern is matched correctly
153 if [[ $STR = $PAT ]]; then
157 # bug in all versions up to and including bash-2.05b
158 if [[ "123abc" == *?(a)bc ]]; then echo ok 42; else echo bad 42; fi
159 if [[ "123abc" == *?(a)bc ]]; then echo ok 43; else echo bad 43; fi