# 总结

**关注作者公众号**： \
&#x20;![](/files/-MRfZZWty4bKGjJ7aqBQ) <br>

## 总结

* [前言](/shellbook/01-chapter10.md#toc_30143_27506_1)
* [Shell 编程范例回顾](/shellbook/01-chapter10.md#toc_30143_27506_2)
* [常用 Shell 编程“框架”](/shellbook/01-chapter10.md#toc_30143_27506_3)
* [程序优化技巧](/shellbook/01-chapter10.md#toc_30143_27506_4)
* [其他注意事项](/shellbook/01-chapter10.md#toc_30143_27506_5)

### 前言

到这里，整个 Shell 编程系列就要结束了，作为总结篇，主要回顾一下各个小节的主要内容，并总结出 Shell 编程的一些常用框架和相关注意事项等。

### Shell 编程范例回顾

TODO：主要回顾各小节的内容。

### 常用 Shell 编程“框架”

TODO：通过分析一些实例总结各种常见问题的解决办法，比如如何保证同一时刻每个程序只有一个运行实体（进程）。

### 程序优化技巧

TODO：多思考，总会有更简洁和高效的方式。

### 其他注意事项

TODO：比如小心 `rm -rf` 的用法，如何查看系统帮助等。

#### 正确使用 `source` 和 `.`

仅使用 `source` 和 `.` 来执行你的环境配置等功能，建议不要用于其它用途。 在Shell中使用脚本时，使用 `bash your_script.sh` 而不是 `source your_script.sh` 或 `. your_script.sh`。

当使用 `bash` 的时候，当前的Shell会创建一个新的子进程执行你的脚本；当使用 `source` 和 `.` 时，当前的Shell会直接解释执行 `your_script.sh` 中的代码。如果 `your_script.sh` 中包含了类似 `exit 0` 这样的代码，使用`source` 和 `.` 执行会导致当前Shell意外地退出。


---

# 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://tinylab-1.gitbook.io/shellbook/01-chapter10.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.
