Linux Gvim Shell If...else statement

Source: Internet
Author: User



#if Else statement, divided into three kinds: if...fi; If ... else ... fi; If ... elif...else...fi
#if Else FI statement syntax
#if [Expression]
#then
# Statement to being executed if expression is true
#else
# Statement to being executed if expression is not true
#fi
#if elif Else FI statement syntax: Which statement executes if the expression is true, and if all false executes the Else statement
#if [Expression 1]
#then
# Statement (s) to BES executed if expression 1 is true
#elif [Expression 2]
#then
# Statement (s) to BES executed if expression 2 is true
#elif [Expression 3]
#then
# Statement (s) to BES executed if expression 3 is true
#else
# Statement (s) to BES executed if no expression is true
#fi


 
 
 1 a=30
 2 b=20
 3 if [ $a == $b ]
 4 then
 5    echo "a is equal to b"
 6 elif [ $a -gt $b ]
 7 then
 8    echo "a is greater than b"
 9 elif [ $a -lt $b ]
10 then
11    echo "a is less than b"
12 else
13    echo "None of the condition met"
14 fi


The #if else statement can also be written as a line and run as a command, as follows:


1 if 2*31+5 ];  Then Echo " true " fi


##if else statements are often used in conjunction with the test command
#test command is used to check if a certain condition is true, similar to []


 
1 num1=$[2*3]
2 num2=$[1+5]
3 if test ${num1} -eq ${num2}
4 then
5     echo ‘The two numbers are equal!‘
6 else
7         echo ‘The two numbers are not equal!‘
8 fi







Linux Gvim Shell If...else statement


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.