- 打印字符串
echo "It is a test"
- 打印特殊字符
echo "\"It is a test\""
# 输出结果
"It is a test"
- 打印变量
# read表示接收执行脚本的输入的第1行
# 编辑
[root@VM-12-15-centos home]# vi test.sh
# 编写如下
#!/bin/sh
read name
echo "$name It is a test"
# 执行
[root@VM-12-15-centos home]# sh test.sh
aa
aa It is a test
- 打印换行
echo -e "OK! \n" # -e 开启转义
echo "It is a test"
# 执行结果
OK!
It is a test
- 打印不换行
#!/bin/sh
echo -e "OK! \c" # -e 开启转义 \c 不换行
echo "It is a test"
# 执行结果
OK! It is a test
- 打印内容写入文件
echo "It is a test" > myfile
- 使用单引号原样输出字符串
echo '$name\"'
# 输出结果
$name\"
- 使用反引号输出当前日期
[root@VM-12-15-centos home]# vi test.sh
# 编写如下
echo `date`
[root@VM-12-15-centos home]# sh test.sh
Mon May 13 19:30:23 CST 2024
标签:shell,centos,打印,echo,命令,sh,test,home
From: https://www.cnblogs.com/dogleftover/p/18189827