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--
Author: Cheng Mo,
www.cnblogs.com/chengmo/archive/2010/10/14/1851434.html
The Linux shell has its own set of flow control statements, including conditional statements (if), loop statements (for,while), and select statements (case). Below I will introduce the following examples, the use of each statement method.
1. Shell conditional statement (if usage)
if statement structure [if/then/elif/else/fi]
if conditional test statement
then
action
[elif conditions
action
else
action
]
fi
If you are not clear about: conditional test statements, you can refer to: linux shell logical operators, logical expressions
Shell commands can be separated by semicolons or newlines. If you want to write more than one command on a line, you can split it by "';".
[chengmo@centos5 ~]$ a=5;if [[ a -gt 4 ]] ;then echo 'ok';fi;
ok
Example: (test.sh)
#!/ bin/sh
scores=40;
if [[ $scores -gt 90 ]]; then
echo "very good! ";
elif [[ $scores -gt 80 ]]; then
echo "good! ";
elif [[ $scores -gt 60 ]]; then
echo "pass! ";
else
echo "no pass! ";
fi;
The test is: [],[],
For,while,until:
for recycling method (for/do/done)
Syntax structure:
1. for... in statements
for variable in seq string
do
action
done
Description: seq string as long as the space character division, each time for... in read, will read the value in order, to the previous variable.
Example (testfor.sh):
#!/ bin/sh
for i in $(seq 10); do
echo $i;
done;
seq 10 produces 1 2 3... 10 spaces separate strings.
2.for((assignment; condition; operation statement))
for((assignment; condition; operation statement))
do
action
done;
Example (testfor2.sh):
#!/ bin/sh
for((i=1;i
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.