The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 07-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The shell has an eerie set of syntax alternatives for conditionals.

The [ is not a traditional delimiter, but the name of a command. The way to use it for multiple expressions is like this:

Code:
if [ "$h" -gt 9 ] && [ "$h" -lt 21 ]; then
  ...
fi
A slightly newer (that is, post-1979 or so ...) syntax is

Code:
if [ "$h" -gt 9 -a "$h" -lt 21 ]; then
  ...
fi
The $((...)) syntax is much newer, and introduces proper arithmetic (including the > and < operators) but is not directly usable as a condition. It simply expands to 0 for false and 1 for true. But of course, you can mix and match:

Code:
if [ $((h > 9 && h < 21)) == 1 ]; then
  ...
fi
Finally, there is the [[ ... ]] conditional, which is probably what you are after:

Code:
if [[ $h > 9 ]] && [[ $h < 21 ]]; then
  ...
fi
The characters which make up the [[ delimiter cannot be separated by whitespace (to the best of my knowledge).