echo
echo - 打印一行文本到标准输出
当然它可以将输入重定向到某个文件中
实例:
oliver@ubuntu:~/temp$ echo "\"yinjianwen\""
"yinjianwen"
oliver@ubuntu:~/temp$
\作为转义字符的作用,和C语言中是相同的
echo -e 表示开启转义
注意:"!\n"这样的组合会被识别为一个指令组合!
oliver@ubuntu:~/temp$ echo -e "OK!\n"
bash: !\n: event not found
oliver@ubuntu:~/temp$ echo -e "OK! \n"
OK!
oliver@ubuntu:~/temp$ echo "OK! \n"
OK! \n
oliver@ubuntu:~/temp$ echo "OK! \ntest"
OK! \ntest
oliver@ubuntu:~/temp$ echo -e "OK! \ntest"
OK!
test
oliver@ubuntu:~/temp$
重定向到文件中
oliver@ubuntu:~/temp$ ls
echo.sh
oliver@ubuntu:~/temp$ echo "It is a test" > echo.sh
oliver@ubuntu:~/temp$
原样输出:
oliver@ubuntu:~/temp$ echo '$name\"'
$name\"
oliver@ubuntu:~/temp$
本文介绍了Linux下echo命令的基本用法及实例,包括如何利用转义字符进行文本格式化,以及如何将输出重定向到文件中。同时展示了如何避免shell对特殊字符的误解析。
2122

被折叠的 条评论
为什么被折叠?



