赞
踩
echo
- display a line of textEcho the STRING(s) to standard output.
echo [ˈekəʊ]:n. 回响,回声,回音,映现 v. 回响,回荡,发出回声,产生回响
(base) yongqiang@yongqiang:~$ man echo
输出内容,然后输出换行符号。
(base) yongqiang@yongqiang:~$ echo "yongqiang"
yongqiang
(base) yongqiang@yongqiang:~$ echo yongqiang
yongqiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo "Yongqiang Cheng"
Yongqiang Cheng
(base) yongqiang@yongqiang:~$ echo Yongqiang Cheng
Yongqiang Cheng
(base) yongqiang@yongqiang:~$
-n
- do not output the trailing newline (取消换行符)取消输出后行末的换行符号,内容输出后不换行。
trail [treɪl]:v. 跟踪,追踪,拖,磨蹭 n. 小径,路径,踪迹,足迹
(base) yongqiang@yongqiang:~$ echo "Yongqiang Cheng"
Yongqiang Cheng
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -n "Yongqiang Cheng"
Yongqiang Cheng(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$
如果加入 -n
选项,则在输出内容结束后,不会换行,直接显示新行的提示符。
(base) yongqiang@yongqiang:~$ echo Yongqiang Cheng
Yongqiang Cheng
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo Yongqiang; echo Cheng
Yongqiang
Cheng
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -n Yongqiang; echo Cheng
YongqiangCheng
(base) yongqiang@yongqiang:~$
加分号表示一条语句的完结。
-e
- enable interpretation of backslash escapes (支持反斜线控制的字符转换)检索语句中的转义符并执行,需要使用双引号 " "
。
If -e
is in effect, the following sequences are recognized:
\\ backslash - 输出 \
\a alert (BEL) - 输出警告音
\b backspace - 退格键,删除左边一个字符
\c produce no further output - 取消输出行末的换行符,和 -n 选项一致
\e escape - Esc 键
\f form feed - 换页符
\n new line - 换行符
\r carriage return - 回车键
\t horizontal tab - 水平制表符
\v vertical tab - 垂直制表符
\0NNN byte with octal value NNN (1 to 3 digits) - 按照八进制 ASCII 码表输出字符,其中 0 为数字 0,NNN 是三位八进制数
\xHH byte with hexadecimal value HH (1 to 2 digits) - 按照十六进制 ASCII 码表输出字符,其中 hh 是两位十六进制数
carriage [ˈkærɪdʒ]:n. 运输,运费,举止,仪态
(base) yongqiang@yongqiang:~$ echo -e "\\"
\
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "\a"
(base) yongqiang@yongqiang:~$
\b
删除左边一个字符。
(base) yongqiang@yongqiang:~$ echo -e "yong\bqiang"
yonqiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "yongqiang\b"
yongqiang
(base) yongqiang@yongqiang:~$
输出内容结束后,不会换行,且 \c
之后的内容不输出。
(base) yongqiang@yongqiang:~$ echo -e "yongqiang"
yongqiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "yongqiang\c"
yongqiang(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "yong\cqiang"
yong(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$
\t
水平制表符,Tab 键。
(base) yongqiang@yongqiang:~$ echo -e "Aaa\tBbb\tCcc"
Aaa Bbb Ccc
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "Aaa\tBbb\tCcc\nDdd\tEee\tFff"
Aaa Bbb Ccc
Ddd Eee Fff
(base) yongqiang@yongqiang:~$
输入八进制,打印对应的 ASCII 码。65 = \0101 = ‘A’
输入十六进制,打印对应的 ASCII 码。65 = \x41 = ‘A’
(base) yongqiang@yongqiang:~$ echo -e "\0101\t\0102\t\0103\n\0104\t\0105\t\0106"
A B C
D E F
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "\x41\t\x42\t\x43\n\x44\t\x45\t\x46"
A B C
D E F
(base) yongqiang@yongqiang:~$
\n
换行符
(base) yongqiang@yongqiang:~$ echo -e "yong\nqiang"
yong
qiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "yongqiang\n"
yongqiang
(base) yongqiang@yongqiang:~$
\f
换页符
(base) yongqiang@yongqiang:~$ echo -e "yong\fqiang"
yong
qiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "yongqiang\f"
yongqiang
(base) yongqiang@yongqiang:~$
\r
光标回到行首,后面输出的内容会覆盖之前的输出,可用于制作进度条。
(base) yongqiang@yongqiang:~$ echo -e "yong\rqiang"
qiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "yongqiang\rcheng"
chengiang
(base) yongqiang@yongqiang:~$
\v
垂直制表符
(base) yongqiang@yongqiang:~$ echo -e "yong\vqiang\vcheng"
yong
qiang
cheng
(base) yongqiang@yongqiang:~$
\e[
是标准格式,代表颜色输出开始。
\e[0m
是标准格式,代表颜色输出结束。
字体颜色:30m
=黑色,31m
=红色,32m
=绿色,33m
=黄色,34m
=蓝色,35m
=洋红,36m
=青色,37m
=白色。
(base) yongqiang@yongqiang:~$ echo -e "\e[30m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[31m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[32m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[33m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[34m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[35m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[36m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[37m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$
字体颜色:1;30m
=亮黑色,1;31m
=亮红色,1;32m
=亮绿色,1;33m
=亮黄色,1;34m
=亮蓝色,1;35m
=亮洋红,1;36m
=亮青色,1;37m
=亮白色。
(base) yongqiang@yongqiang:~$ echo -e "\e[1;30m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;31m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;32m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;33m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;34m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;35m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;36m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;37m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$
\e[
是标准格式,代表颜色输出开始。
\e[0m
是标准格式,代表颜色输出结束。
背景颜色:40m
=黑色,41m
=红色,42m
=绿色,43m
=黄色,44m
=蓝色,45m
=洋红,46m
=青色,47m
=白色。
(base) yongqiang@yongqiang:~$ echo -e "\e[40m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[41m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[42m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[43m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[44m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[45m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[46m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[47m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "\e[1;40m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;41m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;42m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;43m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;44m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;45m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;46m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$ (base) yongqiang@yongqiang:~$ echo -e "\e[1;47m yongqiang \e[0m" yongqiang (base) yongqiang@yongqiang:~$
\033
和 \e
效果相同。
(base) yongqiang@yongqiang:~$ echo -e "\e[4m yongqiang \e[0m"
yongqiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "\033[4m yongqiang \e[0m"
yongqiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -e "\033[4m yongqiang \033[0m"
yongqiang
(base) yongqiang@yongqiang:~$
闪烁显示。
(base) yongqiang@yongqiang:~$ echo -e "\033[5m yongqiang \033[0m"
yongqiang
(base) yongqiang@yongqiang:~$
红色字体,白色背景显示。
(base) yongqiang@yongqiang:~$ echo -e "\e[31;47m yongqiang \e[0m"
yongqiang
(base) yongqiang@yongqiang:~$
-E
- disable interpretation of backslash escapes (default)禁用转义字符。
(base) yongqiang@yongqiang:~$ echo -e "\e[31;47m yongqiang \e[0m"
yongqiang
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo -E "\e[31;47m yongqiang \e[0m"
\e[31;47m yongqiang \e[0m
(base) yongqiang@yongqiang:~$
echo yongqiang cheng
(base) yongqiang@yongqiang:~$ echo yongqiang cheng
yongqiang cheng
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo yongqiang cheng
yongqiang cheng
(base) yongqiang@yongqiang:~$
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。