typora/note/Shell/影响shell程序的内置命令.md

38 lines
351 B
Markdown
Raw Permalink Normal View History

2024-12-11 21:48:55 -05:00
- exit 退出程序
- continue 进行下一次循环
- break 退出循环
- shift 输入参数位移
```
#! /bin/env bash
sum=0
for i
do
let sum+=$i
done
echo $sum
```
```
#! /bin/env bash
sum=0
while [ $# -ne 0 ]
do
let sum+=$1
shift
done
echo $sum
```
```
#! /bin/env bash
sum=0
while [ $# -ne 0 ]
do
let sum+=$1
shift 2
done
echo $sum
```