简介
本文用于日常练习使用
Shell
case-when
、while
、if
、for
如下样例:
#!/bin/bash
# case : bash case.sh start 1 1
#查询变量数目
echo "参数数目: $#"
#case-when
echo "case-when"
case $1 in
"io")
for i in {0..3}
do
vmstat 1 1
done
;;
*)
echo "args is error!!!"
;;
esac
#while
echo "while"
num=$2
while [ $num -eq 1 ]
do
echo "$num==1"
num=$[ num + 1 ]
done
# IF
echo "if"
if [ $3 -eq 2 ]
then
echo "$3 is 2"
elif [ $3 -lt 2 ]
then
echo "$3 -lt 2"
else
echo "$3"
fi
echo "Bye Bye !!!"
两数相加:
#!/bin/bash
num1=$1
num2=$2
num3=$[ num1 + num2 ]
echo $num3
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/271426.html