The IF statement for the shell script

Source: Internet
Author: User

First, preface

In structured programming, there are three main structures: sequential, branching, and cyclic. This shows the importance of branch judgment.

And in shell programming often encountered in the case of judgment, such as: Determine whether the file exists, the directory exists, and so on.

II. structure of the IF statement
if conditions  Then     ... elif conditions    ... Else     ... fi
Iii. branch judgment in the shell

There are several judgments in the shell:

1. String judgments
STR1 =! = str2 When two strings of content are not true at the same time -n str1 when the length of the string is greater than 0 is true -z str1 when the string length is 0 is true str1 when the string is not empty is true 
2. Digital Judgment
N1------le n2 N1 less than equals N2 is true
3. Document Judgment
file The file can be read as true  -w file file can be written  as a true file for real files executable as normal   file files for a directory file  as true file file for characters special files  as true for block special files for true file   The file file is true for the linked file  when the device specified by the descriptor is terminal
4. Combination
-A and -o or !  Non -

The IF statement for the shell script

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.