Control Flow Structure in shell script

Source: Internet
Author: User

I am used to the C/C ++ programming environment, and then switched to shell programming, there is always a strange feeling.

The general if-then-else Function Format in shell is as follows:

If condition 1

Then command 1

Elif condition 2

Then command 2

Else command 3

Fi

In Linux

If the exit status of the command is 0, the exit is successful and there is no error;

If the exit status is 1, the exit fails, and an error occurs somewhere.

If-then-else-FunctionIn, condition 1 is a condition test. If condition 1 returns 0, the test is true, and command 1 is executed. If condition 1 returns 1, Elif is executed.

That is to say, the criterion for determining whether the test is successful is if, rather than the return value.

This is a little different from C/C ++. If you don't pay attention to it, you will get it wrong.

For more information, see:

Linux and unix_shell programming guide 18.3

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.