
Shell 的 echo 指令是用于字符串的输出。命令格式:
echo string当然也可以使用echo实现更复杂的输出格式控制。
echo "It is a test"这里的双引号完全可以省略,以下命令与上面实例效果一致:
echo It is a testecho "\"It is a test\""结果将是:
"It is a test"同样,双引号也可以省略
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
#!/bin/sh
read name
echo "$name It is a test"以上代码保存为 test.sh,name 接收标准输入的变量,结果将是:
[root@www ~]# sh test.sh
OK #标准输入
OK It is a test #输出echo -e "OK! \n" # -e 开启转义
echo "It it a test"输出结果:
OK!
It it a test#!/bin/sh
echo -e "OK! \c" # -e 开启转义 \c 不换行
echo "It is a test"输出结果:
OK! It is a testecho "It is a test" > myfileecho '$name\"'输出结果:
$name\" echo `date`结果将显示当前日期
Tue Aug 30 13:01:53 UTC 2016