You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
echo
|
|
|
|
|
===
|
|
|
|
|
|
|
|
|
|
输出指定的字符串或者变量
|
|
|
|
|
|
|
|
|
|
## 补充说明
|
|
|
|
|
|
|
|
|
|
**echo命令** 用于在shell中打印shell变量的值,或者直接输出指定的字符串。linux的echo命令,在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的,因此有必要了解下echo的用法echo命令的功能是在显示器上显示一段文字,一般起到一个提示的作用。
|
|
|
|
|
|
|
|
|
|
### 语法
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
echo(选项)(参数)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 选项
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
-e:激活转义字符。
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
使用`-e`选项时,若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出:
|
|
|
|
|
|
|
|
|
|
* \a 发出警告声;
|
|
|
|
|
* \b 删除前一个字符;
|
|
|
|
|
* \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 消隐
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->
|