# echo

输出指定的字符串或者变量

## 补充说明

**echo命令** 用于在shell中打印shell变量的值，或者直接输出指定的字符串。linux的echo命令，在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的，因此有必要了解下echo的用法echo命令的功能是在显示器上显示一段文字，一般起到一个提示的作用。

### 语法

```
echo(选项)(参数)
```

### 选项

```
-e：激活转义字符。
```

使用`-e`选项时，若字符串中出现以下字符，则特别加以处理，而不会将它当成一般文字输出：

* `\a` 发出警告声；
* `\b` 删除前一个字符；
* `\c` 不产生进一步输出 (\c 后面的字符不会输出)；
* `\f` 换行但光标仍旧停留在原来的位置；
* `\n` 换行且光标移至行首；
* `\r` 光标移至行首，但不换行；
* `\t` 插入tab；
* `\v` 与\f相同；
* `\\` 插入\字符；
* `\nnn` 插入 `nnn`（八进制）所代表的ASCII字符；

### 参数

变量：指定要打印的变量。

### 实例

用echo命令打印带有色彩的文字：

**文字色：**

```
echo -e "\e[1;31mThis is red text\e[0m"
This is red text
```

* `\e[1;31m` 将颜色设置为红色
* `\e[0m` 将颜色重新置回

颜色码：重置=0，黑色=30，红色=31，绿色=32，黄色=33，蓝色=34，洋红=35，青色=36，白色=37

**背景色** ：

```
echo -e "\e[1;42mGreed Background\e[0m"
Greed Background
```

颜色码：重置=0，黑色=40，红色=41，绿色=42，黄色=43，蓝色=44，洋红=45，青色=46，白色=47

**文字闪动：**

```
echo -e "\033[37;31;5mMySQL Server Stop...\033[39;49;0m"
```

红色数字处还有其他数字参数：0 关闭所有属性、1 设置高亮度（加粗）、4 下划线、5 闪烁、7 反显、8 消隐


---

# 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://hezhiqiang.gitbook.io/linux/ming-ling/echo.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.
