Linux Advanced Bash Programming (Process Control If-else)

Source: Internet
Author: User

One: Condition judgment

if condition
Then
Statements
[elif condition
Then statements. ..]
[Else
Statements ]
fi

Integer comparison:

-lt, less than-le, less than or equal to-eq, equal to-ge, greater than or equal to-GT, greater than-ne, not equal to

Bash Script debug: Bash-x test.sh

Practice:

1: Write a bash program to determine the size of the parameters that are brought in.

650) this.width=650; "Title=" ifelse1. JPG "alt=" wkiom1cd4z7tvqo8aae0quqhyiw626.jpg "src=" http://s1.51cto.com/wyfs02/M01/7E/8D/ Wkiom1cd4z7tvqo8aae0quqhyiw626.jpg "/>

2: Prompt the user to enter a number, need to verify whether to enter a pure number? And judge whether it is odd or even!

Method 1: Use the arithmetic operation expr $n + 1 To determine whether it is a pure number, if it is not a pure number, then the command execution fails, thereby $? nonzero. ($? Indicates the result of the previous line of command 0 is successful, others are not successful)

650) this.width=650; "Title=" Ifelse2. JPG "alt=" wkiom1cd4w_gefa1aadtcfarw-k936.jpg "src=" Http://s2.51cto.com/wyfs02/M00/7E/8D/wKiom1cD4w_ Gefa1aadtcfarw-k936.jpg "/>

Method two: By using grep to determine whether the user's input contains non-numeric, if not included, then output 0, if included, Output 1.

650) this.width=650; "style=" Float:none; "title=" if3. JPG "alt=" wkiom1cd41-xavmyaadwcjzwsls453.jpg "src=" http://s3.51cto.com/wyfs02/M02/7E/8D/ Wkiom1cd41-xavmyaadwcjzwsls453.jpg "/>

Validation results: The script names of the two methods are if2.sh,if3.sh

650) this.width=650; "style=" Float:none; "title=" Ifresult. JPG "alt=" wkiol1cd5avsxttwaagtjrz49zi297.jpg "src=" http://s5.51cto.com/wyfs02/M02/7E/8A/ Wkiol1cd5avsxttwaagtjrz49zi297.jpg "/>


This article is from the "Reminder Flower Rain" blog, please make sure to keep this source http://chenwen.blog.51cto.com/771416/1760727

Linux Advanced Bash Programming (Process Control If-else)

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.