参数
参数 | 用法 | 记忆 |
---|
-e | 解析字符串中的特殊符号 | 解析字符串中的特殊符号 |
-n | 不换行 | 把“-”看作减号,“n”看作newline,“-n”不是新的一行 |
转义字符
使用回车键“enter”五个字母代表“-e”、“-n”、“\t”、“\n”、“\r”;
退格键“backspace”代表“\b”
转义字符 | 用法 | 记忆 |
---|
\t | 制表符(四个空格) | table(键盘上的Tab键) |
\n | 换行且光标移至行首 | 没有减号“-”,所以换行 |
\r | 光标移至行首,但不换行 | 回车键“Enter”的最后一个字母 |
\b | 退格 | 退格键“Backspace”的首字母 |
实例
-e
[aaa@centos ~]$ echo -e "hello\nworld"
hello
world
-n
[aaa@centos ~]$ echo -n "hello"
hello[aaa@centos ~]$
\t
[aaa@centos ~]$ echo -e "hello\tworld"
hello world
\n
[aaa@centos ~]$ echo -en "helloworld\n"
helloworld
\r
[aaa@centos ~]$ echo -e "\thello\rworld"
world hello
\b
[aaa@centos ~]$ echo -e "hello\b"
hello
[aaa@centos ~]$ echo -e "hello\bh"
hellh