shell基础(六)
声明:该笔记为up主 泷羽的课程笔记,本节链接指路。
警告:本教程仅作学习用途,若有用于非法行为的,概不负责。
until循环
- until循环与while循环相反,它会在条件为假时持续执行命令块。
- 写一个0-10的循环代码:
i=0
until [ ! $i -lt 10 ]
do echo $i((i++))
done

case语句
用于从用户那获取输入的一个数值,然后根据输入的值进行不同的处理。
其中-p用于等待输入之前向用户显示提示信息。
read -p "input number:" num
case $num in1)echo you input 1;;2)echo you input 2;;3)echo you input 3;;
esac

基本函数判断与处理
先定义函数名,我们可以利用传参进行输出。
DemoFunc () {echo "hello world"echo "My name is $1:"
}DemoFunc hacker

如果我们想要在外部传参可以改为:
DemoFunc () {echo "hello world"echo "My name is:$1"
}DemoFunc "$1"

