Note:
Format 1, Format 2: one condition one command;
Format 3: One condition two commands;
Format 4: Two conditions three commands, note the wording of the condition.
Example 1:
#!/bin/sh
#ifTest
#to Show the method of If
Echo-e "Enter the first integer:\c"
Read First
Echo-n "Enter The second integer:"
Read SECOND
If ["$FIRST"-GT "$SECOND"]
Then
echo "$FIRST is greater than $SECOND"
elif ["$FIRST"-lt "$SECOND"]
Then
echo "$FIRST is less than $SECOND"
Else
echo "$FIRST is equal to $SECOND"
Fi
Perform:
[Email protected] sh]#./test.sh
Enter the first Integer:7
Enter the second Integer:7
7 is equal to 7
[Email protected] sh]#./test.sh
Enter the first Integer:8
Enter the second Integer:7
8 is greater than 7
[Email protected] sh]#
Example 2:
#!/bin/bash
#5. Sh
Declare
a STRING;
b STRING;
BEGIN
A=$1
B=$2
If ["$a" = "$b"]; then
echo "A=b"
Else
echo "A!=b"
Fi
END;
Linux control structure