# 6. 流程控制

## if-else

```bash
if condition
then
    command1
    command3
    command2
fi
```

```bash
if condition
then 
    command1
    ...
else

    commad1
    ...
fi
```

## if-else-if

```bash
if condition
then
    command1
    commadn2
    ...
elif condition
then
    commadm
    ..
else
    ...
fi
```

## for 循环

```bash
for varname in item1 item2 ... itemN
do
    command1
    command2
    ...
    commandN
done
```

## while 循环

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

## until 循环

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

## case 多分支选择

```bash
case value in
p1) 
    command1
    command2
    ;;
p2)
    command1
    command2
    ;;
esac
```

demo

```bash
echo '输入 1 到 4 之间的数字:'
echo '你输入的数字为:'
read aNum
case $aNum in
    1)  echo '你选择了 1'
    ;;
    2)  echo '你选择了 2'
    ;;
    3)  echo '你选择了 3'
    ;;
    4)  echo '你选择了 4'
    ;;
    *)  echo '你没有输入 1 到 4 之间的数字'
    ;;
esac
```

## break

跳出后续所有的循环

## continue

跳出当前循环


---

# 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://sugar-at.gitbook.io/blog-article/shell/6.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.
