1.官方文档
[root@master soft]# help echo
echo: echo [-neE] [arg ...]
Write arguments to the standard output.
Display the ARGs on the standard output followed by a newline.
Options:
-n do not append a newline
-e enable interpretation of the following backslash escapes
-E explicitly suppress interpretation of backslash escapes
`echo' interprets the following backslash-escaped characters:
\a alert (bell)
\b backspace
\c suppress further output
\e escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\0nnn the character whose ASCII code is NNN (octal). NNN can be
0 to 3 octal digits
\xHH the eight-bit character whose value is HH (hexadecimal). HH
can be one or two hex digits
2.参数
-n :不换行输出
-e :可以识别各种转义符号\t tab键,\n回车
-E :不识别各种转义,与-e相反
>:覆盖重定向
>>>:追加重定向
3.感叹号问题
!被bash解释为取反,因为a不是变量,所以报错
3.1 解决感叹号问题之一
使用单引号
[root@master ~]# echo !a!
-bash: !a!: event not found
[root@master ~]# echo '!a!'
!a!
[root@master ~]# echo "!a!"
-bash: !a!: event not found
[root@master ~]# echo a!
a!
[root@master ~]# echo 'a!'
a!
[root@master ~]# echo "a!"
-bash: !": event not found
3.2 解决感叹号问题之二
[root@master ~]# set +H
[root@master ~]# echo !a!
!a!
[root@master ~]# echo '!a!'
!a!
[root@master ~]# echo "!a!"
!a!
[root@master ~]# echo a!
a!
[root@master ~]# echo !a
!a
[root@master ~]# echo !a!
!a!
root@master ~]# set -H
3.3 给a赋值echo
[root@master ~]# echo !a
echo a=1
a=1
[root@master ~]# echo "!a"
echo "ansible all -m shell -a 'poweroff'"
ansible all -m shell -a 'poweroff'
[root@master ~]# echo '!a'
!a
4.分号问题
分号被bash当做语句结束符,所以在引号外不输出
[root@master ~]# echo “;”
;
[root@master ~]# echo ‘;’
;
[root@master ~]# echo ;
5. echo 分行
默认echo输出自动分行,加-n不自动分行。
6. 颜色输出控制
前景色:重置/默认=0,黑色=30,红色=31,绿色=32,黄色=33,蓝色=34,紫色=35,天蓝色=36,白色=37。
背景色:重置/默认=0,黑色=40,红色=41,绿色=42,黄色=43,蓝色=44,紫色=45,天蓝色=46,白色=47。
样式:1高亮,4下划线,5闪烁。
高亮闪烁下划线,红色前景,蓝色背景
echo -e ‘\e[1;4;5;31;44m blueicex \e[0;0m’
\e[或\033[开头,m结尾,;分割
————Blueicex 2020/03/07 21:24 blueice1980@126.com