显示普通字符串
echo "It is a test"
或
echo It is a test
显示转义字符
echo "\"It is a test \""
或
echo \"It is a test \"
显示变量
read命令从标准输入中读取一行,并把输入行的每个字段的值指定给shell变量
test.sh文件内容为:
read name
echo "$name It is a test"
执行:
sh test.sh
OK
输出:
OK It is a test
显示换行
-e表示开启转义
echo -e "OK! \n"
echo "It is a test"
显示不换行
-e表示开启转义
echo -e "OK! \c"
echo "It is a test"
显示结果定向至文件
echo "It is a test">file
原样输出字符串,不进行转义或取变量(用单引号)
echo '$name'
显示命令结果
显示当前日期
echo `date`