> For the complete documentation index, see [llms.txt](https://coolconan.gitbook.io/roadmap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coolconan.gitbook.io/roadmap/basics/basic-terminal-usage/shell/6.-liu-cheng-kong-zhi.md).

# 流程控制

## if else

```bash
if [ expression ]; then
  statement
else
  statement
fi


if [ expression ]; then
  statement
elif [ expression ]; then
  statement
else
  statement
fi
```

## 循环

### for

```bash
for i in item1 item2 ... itemN
do
    statement
    ...
    statement
done

arr=(1 2 3)
for i in ${arr[@]}
do
    statement
    ...
    statement
done
```

### while

```bash
while condition
do
    command
done
```

无限循环

```bash
while :
do
  # command
done

while true do command done

for (( ; ; )) do command done
```

### until

```bash
until condition
do
    command
done
```

### 跳出循环

#### break

#### continue

## case

```bash
case $var in
  pattern)
    statement
    ;;
  *)
    statement
    ;;
esac
```
