Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1
set number2=10
set number3=5

if      (number1    >   number2)        then
echo "number1 is greater than number2"
else
echo "number1 is not greater than number2"
endif

if      (number1    >=  number3)    then
echo "number1 is greater than or equal to number3"
else
echo ""number1 is not greater than or equal to number3"
endif

if      (number1    <   number2)        then
echo ""number1 is less than number2"
else
echo ""number1 is not less than number2"
endif

if      (number1    <=  number3)    then
echo ""number1 is less than or equal to number3"
else
echo ""number1 is not less than or equal to number3"
endif

When executing the shell program compare2, you get the following results:


Click here to view code image
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
-e—Determines whether a file exists
-f—Determines whether a file is a regular file
-o—Determines whether a user is the owner of a file
-r—Determines whether read permission is set for a file
-w—Determines whether write permission is set for a file
Free download pdf