34.3. Tests and Comparisons: Alternatives

For tests, the [[ ]] construct may be more appropriate than [ ]. Likewise, arithmetic comparisons might benefit from the (( )) construct.
   1 a=8
   2 
   3 # All of the comparisons below are equivalent.
   4 test "$a" -lt 16 && echo "yes, $a < 16"         # "and list"
   5 /bin/test "$a" -lt 16 && echo "yes, $a < 16" 
   6 [ "$a" -lt 16 ] && echo "yes, $a < 16" 
   7 [[ $a -lt 16 ]] && echo "yes, $a < 16"          # Quoting variables within
   8 (( a < 16 )) && echo "yes, $a < 16"             # [[ ]] and (( )) not necessary.
   9 
  10 city="New York"
  11 # Again, all of the comparisons below are equivalent.
  12 test "$city" \< Paris && echo "Yes, Paris is greater than $city"  # Greater ASCII order.
  13 /bin/test "$city" \< Paris && echo "Yes, Paris is greater than $city" 
  14 [ "$city" \< Paris ] && echo "Yes, Paris is greater than $city" 
  15 [[ $city < Paris ]] && echo "Yes, Paris is greater than $city"    # Need not quote $city.
  16 
  17 # Thank you, S.C.