echo string
您可以利用echo实现更繁芜的输出格式掌握。
1.显示普通字符串:
echo \"大众It is a test\"大众
这里的双引号完备可以省略,以下命令与上面实例效果同等:

echo It is a test
2.显示转义字符
echo \"大众\\"大众It is a test\\"大众\公众
结果将是:
\"大众It is a test\"大众
同样,双引号也可以省略
3.显示变量
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
#!/bin/shread nameecho \"大众$name It is a test\"大众
以上代码保存为 test.sh,name 吸收标准输入的变量,结果将是:
[root@www ~]# sh test.shOK #标准输入OK It is a test #输出
4.显示换行
echo -e \公众OK! \n\公众 # -e 开启转义echo \"大众It it a test\"大众
输出结果:
OK!It it a test
5.显示不换行
#!/bin/shecho -e \"大众OK! \c\公众 # -e 开启转义 \c 不换行echo \"大众It is a test\"大众
输出结果:
OK! It is a test
6.显示结果定向至文件
echo \"大众It is a test\"大众 > myfile
7.原样输出字符串,不进行转义或取变量(用单引号)
echo '$name\\公众'
输出结果:
$name\\公众
8.显示命令实行结果
echo `date`
把稳: 这里利用的是反引号 `, 而不是单引号 '。
结果将显示当前日期
Thu Jul 24 10:08:46 CST 2014