2-5 shell 流程控制
作者:
AntKing | 来源:发表于
2020-02-18 15:58 被阅读0次
num1=100
num2=200
if [ $num1 -eq $num2 ]
then
echo "num1 == num2"
elif [ $num1 -gt $num2 ]
then
echo "num1 > num2"
else
echo "num1 <= num2"
fi
array=("item1" "item2" "item3")
for (( i=0;i<${#array[@]};i++)) do
#${#array[@]}获取数组长度用于循环
echo ${array[i]}
done
for element in ${array[@]}
#也可以写成for element in ${array[*]}
do
echo $element
done
for i in "${!array[@]}";
do
printf "%s\t%s\n" "$i" "${array[$i]}"
done
while [ $num1 -lt $num2 ]
do
echo "num1 < num2"
break
done
USER="testing"
case $USER in
rich | barbara)
echo "Welcome, $USER"
echo "Please enjoy your visit"
;;
testing)
echo "Special testing account"
;;
jessica)
echo "Do not forget to log off when you're done"
;;
*)
echo "Sorry, you are not allowed here"
;;
esac
本文标题:2-5 shell 流程控制
本文链接:https://www.haomeiwen.com/subject/chigfhtx.html
网友评论