【流程控制】
【IF THEN】
#!/bin/bash
read -p 'plese input :' var
if
elif
else
fi
$$ pid
$* 命令后的参数全部显示一遍
$@ 同上
$# 命令后参数数量
$? 上一条子命令是否执行成功
检查nginx是否开启
#!bin/bash
ps aux |grep nginx |grep -v 'grep'
echo $?
if[$? -ne 0]
then
systemctl start nginx
else
fi
【while】
while :
do
free
sleep 29
clear
done
while [ Scount -le 10 ]
do
echo Scount
((count++))
done
while :
do
clear
read -p 'please input your name: 'name
read -p 'please input your password: ' psd
if [ -z $name ] || [ -z $psd ]
then
continue
fi
if [ $name = 'alex' ] && [ $psd = '1234' ]
then
echo 'login successful ,welcome'
while :
do
read -p 'please input your cmd: 'cmd
if [ "$cmd" = 'quit' ]
then
break
fi
$ cmd
doen
else
echo 'ueername or password is error'
fi
done
【FOR】
for i in {1...253}
do
ping -cl 192.168.16.$1 &> /dev/null
if [ $? -ne 0]
then
echo "192.168.16.$i is available"
else
echo "192.168.16.$i is unavailable"
fi
done
【case】
#Python 没有此语法
read -p '>>: ' uname
case $uname in
root)
echo "welcome $uname"
;;
seker)
echo "welcome $uname"
;;
default)
echo "welcome $uname"
;;
*)
echo "no kind of user $uname"
esac
【函数】
函数定义:
function abc(){echo 'aaa';echo 'bbbb';}
调用:
abc
set 查看
function install(){
echo 'install'
}
function start(){
echo 'start'
}
if [ "$1" = 'install' ]
then
install
elif [ "$1" = 'start' ]
then
start
else
echo 'commond can not found'
fi