注:此博客使用的是Bash shell
- 显示字符
echo "My name is Queue"
echo My name is Queue
*双引号可省略
- 显示转义字符
echo "\"My name is Queue\""
#输出:
"My name is Queue"
- 接收变量,并显示
read _name
echo "My name is ${_name}"
cjs@Queue:~$ ./boo.sh
Queue
My name is Queue
- 显示/关闭换行
echo "OK"
echo "Good"
#输出:
OK
Good
echo -e "OK \n"
echo "Good"
#输出:
OK
Good
echo -e "OK \c"
echo "Good"
#输出:
OK Good
- 显示结果定向至文件
echo "It is a test" > myfile
- 原样输出字符串,不进行转义或取变量(用单引号)
echo '$name\"'
#输出:
$name\"
- 显示命令执行结果
echo `date`
#输出:
2020年 07月 26日 星期日 15:18:42 CST