Categories
Unix Notes

Short-circuit shell commands

mac 131 work % [[ "a" > "A" ]] && echo fred
fred
mac 132 work % [[ "a" > "A" ]] || echo fred
mac 133 work % [[ "a" > "A" ]] && [[ "a" < "n" ]] && echo fred
fred
mac 138 work % foo="9"
mac 139 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 140 work % echo $foo
defaultString
mac 141 work % foo=" Some String"
mac 142 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 143 work %
mac 143 work % echo $foo
defaultString
mac 144 work % foo="Some String"
mac 145 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 146 work % echo $foo
Some String
mac 147 work % foo=""
mac 148 work % [[ "$foo" < "A" ]] && foo="defaultString"
mac 149 work % echo $foo
defaultString
mac 150 work %