If-then and If-then-else statement

Source: Internet
Author: User

1. Using the If-then statement

Structured command, the primary type is the If-then declaration. If-then For example, the following statement format:

If Commandthen     COMMANDSFI
Suppose you are using If-then statements from other programming languages. Such a form may be confusing to you. In other programming languages. The object after the IF statement is an equation to test whether the value is true or false.

Assuming that the command's exit status code is 0 (the command runs successfully), the command in the then section is run. Suppose the exit status code for this command is something else. That then part of the command will not be run, and the bash shell will continue to run the next command in the script.

Here are some simple examples to explain this concept:

$ cat if_then.sh

#!/bin/bashif Test 1 = 2then    echo "It worked" fi

At this point the execution if_then will not print ' It worked ', change to such as the following will be found, then after the echo "it worked" will be executed.

#!/bin/bashif Test 1 = 1then    echo "It worked" fi





Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

If-then and If-then-else statement

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.