From: http://m.jb51.net/article/56553.htm This article mainly introduced the shell script if condition judgment and the judgment condition summary, this article first gave the IF condition judgment the grammar, then gave the commonly used judgment
If the score is 1-59, you must retake 60-79, good 80-90, excellent 90-100, and receive a scholarship.
#! /Bin/bash
Read-P "Enter your score" sta
If [-Z $ sta]
Then
Echo "You did not enter the score"
Read-P "Enter your score" sta
If [-Z $
Shell script IF condition judgment and judgment condition details, shellifPreface:
No matter what programming language, conditional judgment is indispensable. SHELL is no exception.
if list thendo something hereelif list thendo another thing
The Shell has three kinds of if ... else statements:1.if. FI statement;2.if ... else ... fi statement;3.if. Elif ... else .... fi statement.If ... fi statementSyntax for the IF ... else statement:if [Expression] Then If Truefi Note: There must
Binary comparison operators, comparing variables or comparing numbers.Note the difference between a number and a string.1. Integer comparison[CPP]View PlainCopyprint?
-eq equals, such as:if [ "$a"-eq " $b"]
-ne not equal to, such as:if [ "$a"
1) What is the function of the IF condition control statement?The shell script is also a weak scripting language and supports if conditional control statements.2) If the structure syntaxSingle BranchIfThenFiDual
Presumably everyone knows "if ... So ... " The application of this grammar!Of course, Linux for this kind of usage is also considered, many times we need to write a shell script, it is unavoidable to avoid the IF statement.For example: Determine if
Objective:No matter what programming language is inseparable from conditional judgment. The shell is no exception.Copy CodeThe code is as follows:If List ThenDo something hereElif List ThenDo another thing hereElseDo something else hereFiEX1:Copy
Shell script, if judgment statement error [: Too many arguments
I have encountered two situations:
1, the first situation is that the Internet, you can say, the string variable may exist in a space, shell resolution when it is considered to be more
(1) If statement[Email protected]:/mnt/shared/shellbox/shellif# cat shellif.sh #!/bin/bash# judgment string if ["$" = "Hello"]then echo "\$1= $ "fi# judgment number, if () mode can only be used under bash, not under sh if (>) then echo"
Unlike Java, PHP and other languages, the process control of SH is not NULL, such as:
Copy Code code as follows:
if (Isset ($_get["Q"])) {
Search (q);
}
else {
Doing nothing
}
?>
You can't write this in Sh/bash,
Design a prompt menu for user selection, and perform operations and display based on user selection.
Menu: 1. Start vi Editor 2. Start x-windows and enter the graphic interface 3. Start the background printing process. 4. Exit ctrl + c.
#!
[-A file] true if the file exists. [-B file] If the file exists and is a special block file, it is true. [-C file] If the file exists and is a special word file, it is true. [-D file] If the file exists and is a directory, it is true. [-E file] If
-S file file is somefile 0 o'clock
[f]: Determines whether it is a file [-
X "/bin/ls"]: Determines whether/BIN/LS exists and has executable permissions
[-n "$var]": Judge $va R variable has a value
["$a" = "$b"]: To determine if $a and $b
Objective:no matter what programming language is inseparable from conditional judgment. The shell is no exception.
Copy Code code as follows:
If List Then
Do something here
Elif List Then
Do another thing
Else
Do something
Something written in PHP. Some small things may be useful sometimes! 1. obtain the client IP address functiongetip () {if (! Empty ($ _ SERVER [HTTP_X_FORWARDED_FOR]) {proxy usage $ tipsplit (, $ _ SERVER [HTT some things may be useful sometimes!
1
/********************************************************************* * Author : Samson * Date : 05/07/2014 * Test platform: * Mint 15-3.8.13.13 * GNU bash, version 4.2.45 * *********************************************
Some little things written in PHP may sometimes be used!
1. obtain the client IP address.
Function getip (){
If (! Empty ($ _ SERVER ["HTTP_X_FORWARDED_FOR"]) {// proxy usage
$ Tip = split (",", $ _ SERVER ["HTTP_X_FORWARDED_FOR"]);
$ Cip = $
**************************************** *******************
/*************************************** ******************************* Author: Samson* Date: 05/07/2014* Test platform:* Mint 15-3.8.13.13* GNU bash, version 4.2.45***********************
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.