语法:echo string
echo "It is a test" 输出:It is a test
echo "\"It is a test\"" 输出:"It is a test"
(注意echo在使用转意字符时 " 的位置)
一、显示变量
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量。
# test.sh文件
#!/bin/sh
read name
echo "$name It is a test"
为上面脚本设置可执行权限,并执行脚本:
$ chmod +x test.sh
$ ./test.sh
输出:
OK #标准输入
OK 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
三、不用e进行转义
echo '$name\"' #(用单引号)
输出:$name\"
四、显示命令执行结果
echo `date` #显示当前日期
输出:Thu Jul 24 10:08:46 CST 2014
五、把显示结果输入到某一文件下
echo "It is a test" > myfile
把显示结果It is a test输入到文件myfile下