echo 是主要的文本输出命令,在unix shell 中使用的频率相当的高,主要用来显示执行的log信息.
命令格式: echo string
1.显示普通字符串:
echo "It is a test"
这里的双引号完全可以省略
echo It is a test 效果与上面一致
2.显示转义字符
echo "\"It is a test\""
结果将是: "It is a test"
同样,双引号也可以省略
3.显示变量
read name (输入OK)
echo "$name It is a test"
结果将是: OK It is a test
同样双引号也可以省略
如果变量与其它字符相连的话,需做如下处理:
read mouth (输入8)
echo "${mouth}-1-2009"
结果将是: 8-1-2009
4.显示换行
echo "OK!\n"
echo "It it a test"
5.显示不换行
echo "OK!\c"
echo "It is a test"
6.显示结果定向至文件
echo "It is a test" > myfile
7.原样输出字符串,不进行转义或取变量(用单引号)
echo '$name\"'
8.显示命令执行结果
echo `date`
结果将显示当前日期