echo输出命令
in SHELL脚本攻略笔记 with 0 comment
echo输出命令
in SHELL脚本攻略笔记 with 0 comment

echo 两种输出方式

“输出内容”
‘输出内容’

例一:

echo "Hello world!" #不会自动转义,无法打印特殊符号

打印结果:

-bash: !": event not found

例二:

echo "Hello world\!" #添加转义符\后即可正常输出

打印结果

Hello world\!

例三:

echo 'Hello world!' #''会将字符原封不动的输出

打印结果:

Hello world!
-n echo输出默认会自动添加换行符参数可以忽略结尾的换行符
-e 可以转义特殊符号并正常输出
echo -e "1\t2\t3"

输出:

1 2 3

echo 打印彩色输出:

字体颜色码:重置=0,黑色=30,红色=31,绿色=32,黄色=33,蓝
色=34,洋红=35,青色=36,白色=37

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

输出:

This a red text
\e[1,31m将颜色设置为红色,\e[0m将颜色重置

背景色码:重置=0,黑色=40,红色=41,绿色=42,黄色=43,
蓝色=44,洋红=45,青色=46,白色=47

echo -e "\e[1;42m Green Background \e[0m"

输出:

Green Background
The article has been posted for too long and comments have been automatically closed.