DAY11 Shell Script Basics (enginner05-2)

Source: Internet
Author: User

Vi. condition testing and selection 6.1 test expression

-file Status Test

6.1.1 [-E file]

File exists with a value of true;file does not exist as false

6.1.2 [-D file]

File exists and is a directory with a value of true;file does not exist as false

6.1.3 [-F file]

File exists and the value for True;file does not exist as false

6.1.4 [-R File]

File has r permission with a value of True;file without r permission and a value of false

6.1.5 [w file]

File has W permission with a value of True;file without W permission and a value of false

6.1.6 [x file]

File has x permission with a value of true;file without x permission and a value of false
-Integer size Test

6.1.7 [X-gt y]

X>y

6.1.8 [X-ge y]

X≧y
Greater than or equal

6.1.9 [X-eq y]

X=y
Equals

6.1.10 [X-ne y]

X!=y
Not equal to

6.1.11 [X-lt y]

x< y
Less than

6.1.12 [X-le y]

X≦y
Less than or equal

-String test

6.1.13 [' x ' = = ' Y ']

' X ' is the same as ' Y '
String test

6.1.14 [' x '! = ' Y ']

' x ' differs from ' y '
String test

6.1.15 [-N "string"]

Determines whether a string has a value, has a value of true, and has no value of false

6.1.16 [-Z "string"]

Determines whether a string is empty, is null, is true, is not NULL, or FALSE

-Multiple criteria determination

6.1.17-a

And and

6.1.18-o

OR OR

6.2 If condition test 6.2.1 if single loop

if condition test; then
Command XX
Fi

6.2.2 If double loop

if condition test; then
Command XX
Else
Command yy
Fi

6.2.3 If multi-loop

if condition test; then
Command XX
elif condition Test 1;then
Command yy
Else
Command ZZ
Fi

6.2.4 the difference between empty value and no

A null value indicates that the value is empty
There is no indication that there is no
"$" = = Redhat #给变量加上双引号可以将 "No" into "null"
Examples of scripts:

#!/bin/bash   if [ "$1" == redhat ];then        echo fedora   elif [ "$1" == fedora ];then        echo redhat   else         echo ‘/root/foo.sh redhat|fedora‘ >&2 # >&2表示这个echo为错误输出fi
6.3 For loop structure

Perform the same operation repeatedly, depending on the value of the variable, until the variable has no value and exits the loop
For variable name in value list
Do
Command XX
Done

DAY11 Shell Script Basics (enginner05-2)

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.