"Shell" conditional judgment

Source: Internet
Author: User

expression format for conditional judgments:

File Judging type:

[[Email protected] ~]# [-E/ROOT/1] && echo yes | | echo no  #注意 [] inside the space, the first command is true print Yes, otherwise print noyes[[email protected] ~]# [-F/ROOT/1] && echo yes | | Echo no   yes[ [Email protected] ~]# [-D/ROOT/1] && echo yes | | Echo No No

File permission to determine the type:

[[Email protected] ~]# [-R/ROOT/1] && echo yes | | echo no yes[[email protected] ~]# [-X/ROOT/1] && echo yes | | echo no no[[email protected] ~]# [-W/ROOT/1] && echo yes | | Echo No Yes

File comparison and judgement type:

[[Email protected] ~]# [  /root/1-NT/ROOT/2] && echo yes | | echo no no[[email protected] ~]# [  /ROOT/1- OT/ROOT/2] && echo yes | | echo no yes[[email protected] ~]# [  /root/1-EF/ROOT/2] && echo yes | | echo no no[[email protected] ~]# ln
   1  3[[email protected] ~]# [  /root/1-EF/ROOT/3] && echo yes | | Echo No Yes

 Integer comparison judgment:

[[Email protected] ~]# [4-eq 4] && echo yes | | echo No  #等于yes [[email protected] ~]# [4-ne 4] && echo yes | | echo no  # #不等于no [[email protected] ~]# [5 -GT 4] && echo yes | | Echo No  # #大于yes [[email protected] ~]# [5-LT 4] && echo yes | | echo no  # #小于no [[email protected] ~]# [5 -ge 4] && echo yes | | Echo No   # #大于等于yes [[email protected] ~]# [5-le 4] && echo yes | | echo no  # #小于等于no

String-Judging:

[[Email protected] ~]# [-Z $a] && echo yes | | Echo No  # #判断为空no [[email protected] ~]# [-n $a] && echo yes | | echo no  # #判断非空yes [[email protected] ~]# b= Abc[[email protected] ~]# [$a = = $b] && echo yes | | echo Noyes[[email protected] ~]# [$a! = $b] && echo yes | | Echo Nono

Multi-Conditional judgment:

[[Email protected] ~]# [-N $b-Z $a] && echo yes | | Echo No  # #与no [[email protected] ~]# [-N $b-O-Z $a] && echo yes | | echo no  # #或yes

  

"Shell" conditional judgment

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.