Shell Exercise 1 Writing shell conditional sentence exercises

Source: Internet
Author: User

Instance one, compare two integer sizes
#!/bin/Bash while true DoRead-P"Please input the int nums:"a BExpr$a + $b +0>/dev/NULL 2>&1 #判断是否为整数    if[$?-eq0];Then #返回值是否为0        if[$a-gt $b]; Then           Echo "$a > $b"Exit0        elif[$a-lt $b]; Then           Echo "$a < $b"Exit0        Else[$a-eq $b]Echo "$a = $b"Exit0        fi    fi Done
Example two, test statement and if condition sentence mixed use, through directory installation LAMP,LNMP
directory Installation: #!/bin/SHPath=/server/scrips[! -D"$path"] &&mkdir$path-P#menuCat<<END1. [InstallLamp]2. [InstallLnmp]3. [Exit] pls input the num you wang:endread numExpr$num +1&>/dev/NULLif[$?-ne0]; Then   Echo "The num You input must is {1|2|3}"Exit1fi[$num-eq1]&&{    Echo "start install lamp."    Sleep 2; [ -X"$path/lamp.sh"]||{    Echo "does not exist or can is not exec."Exit1} $path/lamp.SH#source $path/lamp.SHExit $?}if[$num-eq2]; Then   Echo "start install LNMP."   Sleep 2; if[-X"$path/lamp.sh"]; Then$path/lnmp.SH#source $path/lamp.SHExit $?Else        Echo "does not exist or can is not exec."Exitfifiif[$num-eq3]; Then    EchoBye Exit3fi[[ ! $num =~[1-3]] &&{    Echo "The num You input must is {1|2|3}"    Echo "Input ERROR"Exit4}

Shell Exercise 1 Writing shell conditional sentence exercises

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.