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)