Cloud computing courseware outline cloud computing development programming tutorial learning route structure conditions:
Shell programming condition of the structure
No.1 if conditional syntax
The first line: if conditional statement Statement contents [] in the condition that the outside with ";" and then separated, then representatives of the next line after completion of the interpretation
The second line: statement when the condition is true, execution
Third row: show judgment when the condition is not satisfied, then matched by statements to the else and execute else statements
Fourth line: When the condition is not satisfied, execution of sentence
The fifth line: to end the if statement block
- Test for existence
if [Test Condition]; then
Test conditions statement is True, execution
else
Test conditions statement is False, execution
be
[root@bavdu shell_s]# vim if_daemon06.sh
#!/usr/bin/env bash
#
Author: bavdu
Email: [email protected]
Github: https://github.com/bavdu
if [ -d file001 ];then
printf "file001 is already exist.\n"
else
printf "file001 is not exist.\n"
be
[root@bavdu shell_s]# sh if_daemon06.sh
file001 is not exist.
It was carried out to determine the current directory can be added to the sentence to determine the precise path
[-E dir | file] there is the presence of both can also determine whether a file directory
[-D dir] determines whether a directory exists
If [-f file] judgment file exists
If [-r file] current user has read access to the file
If [-w file] current user has write access to the file
If [-x file] current users of the file has execute permissions - numerical comparison between the size of
#!/usr/bin/env bash
#
Author: bavdu
Email: [email protected]
Github: https://github.com/bavdu
read -p "Please input your numbers: " varName
if [ $varName -gt 0 ];then
printf "$varName is more than 0.\n"
else
printf "$varName is less than 0.\n"
be
[root@bavdu shell_s]# sh if_daemon07.sh
Please input your numbers: 29
varName is more than 0.
[root@bavdu shell_s]#
Need back
[1 -gt 10] is greater than
[1 -lt 10] is less than
[1 -eq 10] is equal to
[1 -ne 10] is not equal to
[1 -ge 10] greater than or equal
[1 -le 10] or less