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 # unset variables don't need to be quoted
30 # the ==/= and != operators do pattern matching
31 [[ $TDIR == /usr/homes/* ]]
34 # ...but you can quote any part of the pattern to have it matched as a string
35 [[ $TDIR == /usr/homes/\* ]]
38 [[ $TDIR == '/usr/homes/*' ]]
41 # if the first part of && fails, the second is not executed
42 [[ -n $UNSET && $UNSET == foo ]]
45 [[ -z $UNSET && $UNSET == foo ]]
48 # if the first part of || succeeds, the second is not executed
49 [[ -z $UNSET || -d $PWD ]]
52 # if the rhs were executed, it would be an error
53 [[ -n $TDIR || $HOME -ef ${H*} ]]
56 [[ -n $TDIR && -z $UNSET || $HOME -ef ${H*} ]]
59 # && has a higher parsing precedence than ||
60 [[ -n $TDIR && -n $UNSET || $TDIR -ef . ]]
63 # ...but expressions in parentheses may be used to override precedence rules
64 [[ -n $TDIR || -n $UNSET && $PWD -ef xyz ]]
67 [[ ( -n $TDIR || -n $UNSET ) && $PWD -ef xyz ]]
70 # some arithmetic tests for completeness -- see what happens with missing
71 # operands, bad expressions, makes sure arguments are evaluated as
72 # arithmetic expressions, etc.
101 # more pattern matching tests
103 [[ $filename == *.c ]]
108 [[ $filename == *.c ]]
111 # the extended globbing features may be used when matching patterns
116 [[ $arg == -+([0-9]) ]]
121 [[ $arg == -+([0-9]) ]]
125 [[ $arg == ++([0-9]) ]]
128 # make sure the null string is never matched if the string is not null
132 if [[ $STR = $PAT ]]; then
136 # but that if the string is null, a null pattern is matched correctly
140 if [[ $STR = $PAT ]]; then