bash语句总结

shell逻辑语句总结

if else elif

1
2
3
4
5
6
7
8
9
if expr1
then
commands
elif expr2
then
commands
else
commands
fi


while

1
2
3
4
while expr
do
commands
done

for

1
2
3
4
for x in lists
do
commands
done

case

1
2
3
4
5
6
7
8
9
10
11
case expr in
pattern1)
commands
;;
pattern2)
commands
;;
*)
commands
;;
esca

until

和while差不多但是,当为错误时进入循环,而不是正确进入循环

1
2
3
4
until expr
do
commands
done

break&continue

1
2
3
break [n]

continue [n]

select

实际上这并不是一个逻辑语句,其主要用于创建菜单。并且其是一个死循环,记得使用break语句来退出循环。

1
2
3
4
select x in lists
do
commands
done

shift

1
shift [n]

参考资料

https://math.ecnu.edu.cn/~jypan/Teaching/Linux/Linux08/lect12_Shell_Prog.pdf

https://math.ecnu.edu.cn/~jypan/Teaching/Linux/Linux08/lect14_Review.pdf


bash语句总结
https://ysc2.github.io/ysc2.github.io/2023/12/12/bash语句总结/
作者
Ysc
发布于
2023年12月12日
许可协议