In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Conditional testing:
1. File testing
2. Integer test
3. String and logic testing
If statement:
1. If single branch statement
2. If double-branch statement
3. If multi-branch statement
4. If nested statement
Test command:
Test whether a specific expression is valid, and when the condition is true, the return value of the test statement is 0, otherwise it is another value.
Format 1:test conditional expression format 2: [conditional expression] / / Note blank file Test: format: [operator file or directory] commonly used test operators: 1,-d: test whether it is a directory (Directory) 2,-e: test whether a directory or file exists (Exist) 3,-f: test whether it is a file (File) 4, -r: test whether the current user has permission to read (Read) 5,-w: test whether the current user has permission to write (Write) 6,-x: test whether the current user has permission to execute (eXcute) example: method 1: test-d / etc/sysconfig (test whether there is a sysconfig file or directory in the etc directory) echo $? If the output of this file is 0) method 2: [- d / etc/sysconfig] echo $? (for conditional judgment, if the output of this file is non-0 That is, 1) integer value comparison: format: [integer 1 operator integer 2] commonly used test operators: 1,-eq: equal to (Equal) 2,-ne: not equal to (Not Equal) 3,-gt: greater than (Greater Than) 4,-lt: less than (Lesser Than) 5,-le: less than or equal to (Lesser or Equal) 6,-ge: greater than or equal to (Greater or Equal) Demo1:
Purpose: check the directory to see if there are any files we need, and if not, create them directly. The specific operations are as follows:
[root@localhost ~] #! Test-e / etc/ssc & & touch / etc/ssc (check if there is a ssc file in the etc directory, if not created directly in this directory) [root@localhost ~] # cd / etc (verify: enter the etc directory) [root@localhost etc] # ls (view details At this point you can find the sscw file we created) string comparison: format 1: [string 1 = string 2] [string 1! = string 2] format 2: [- z string] commonly used test I operator: 1, =: string content is the same 2,! =: string content is different! Express the opposite meaning 3,-z: string content is empty logic test: format 1: [expression 1] operator [expression 2]. Format 2: command 1 operator command 2. Common test operators: 1,-an or & &: logic and, "and" means 2,-o or | |: logic or, "or" means 3! Logic No 1. Single branch structure:
2. Double branch structure:
3. Multi-branch structure:
Application example of if statement: 1. Single branch if statement 2. Two-branch if statement:
Determine whether the target host is alive or not, and display the test results
3. Multi-branch if statement:
Judge the range of scores and divide them into excellent, qualified and unqualified third gears
Demo2 (judging performance): use single branch implementation: vim source.shemaking cards bintablebashread-p "Please enter the integer" srcif [$src-le 50] then echo "number too small" fichmod + x source.sh./source.sh uses two-branch implementation: (enter into the created execution file for modification) vim source.shemaking bin.bashread-p "Please enter the integer" srcif [$src-le 50] then echo "number too The small "else echo" number is too large "fi uses multi-branch implementation: (enter the created execution file to modify) vim source.shallowandbin.bashread-p" Please enter the integer "srcif [$src-ge 85] & & [$src-le 100] then echo" $src excellent "elif [$src-ge 70] & & $src-le 84] then echo" $src qualified "else echo" failed fiDemo3 " Experimental environment: running race Enter the finals within 10 seconds. After entering the gender, you will be prompted to enter the male group or the female group, using multiple judgments and nested if to achieve.
Enter the contents in the execution file as shown below:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.