if [ $number1 -gt $number2 ]; then
echo "number1 is greater than number2"
else
echo "number1 is not greater than number2"
fi
if [ $number1 -ge $number3 ]; then
echo "number1 is greater than or equal to number3"
else
echo "number1 is not greater than or equal to number3"
fi
if [ $number1 -lt $number2 ]; then
echo "number1 is less than number2"
else
echo "number1 is not less than number2"
fi
if [ $number1 -le $number3 ]; then
echo "number1 is less than or equal to number3"
else
echo ""number1 is not less than or equal to number3"
fi
When you execute the shell program, you get the following results:
Click here to view code image
number1 is equal to number3
number1 is not equal to number2
number1 is not greater than number2
number1 is greater than or equal to number3
number1 is less than number2
number1 is less than or equal to number3
File Operators
You can use the following operators as file comparison operators:
-d—Determines whether a file is a directory
-f—Determines whether a file is a regular file
-r—Determines whether read permission is set for a file
-s—Determines whether a file exists and has a length greater than zero
-w—Determines whether write permission is set for a file
-x—Determines whether execute permission is set for a file
Assume that a shell program called compare3 is in a directory with a file