# 流程控制

## 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://coolconan.gitbook.io/roadmap/basics/basic-terminal-usage/shell/6.-liu-cheng-kong-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
