2.5 流程控制
2.5.1 if语法
1、语法格式
if condition
then
statements
[elif condition
then statements. ..]
[else
statements ]
fi
2、示例
#!/bin/bash read -p "please input your name:" NAME ###read命令用于从控制台读取输入数据 printf '%s\n' $NAME if [ $NAME = root ] ##注意if和后面的[]有间距 then echo "hello ${NAME},welcome!" elif [ $NAME = toto ] then echo "hello ${NAME},welcome!" else echo "SB,get out here!" fi |
脚本内容截图:
3、判断条件
1/ 条件判断基本语法
[ condition ] ()
command1
command2
...
commandN
;;
esac