shell脚本之echo(五)

来源:互联网 发布:男士去角质 知乎 编辑:程序博客网 时间:2024/06/01 09:29
1.显示普通字符串:echo "It is a test"这里的双引号完全可以省略,以下命令与上面实例效果一致:echo It is a test2.显示转义字符echo "\"It is a test\""结果将是:"It is a test"同样,双引号也可以省略3.显示变量read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量#!/bin/shread name echo "$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 test5.显示不换行#!/bin/shecho -e "OK! \c" # -e 开启转义 \c 不换行echo "It is a test"输出结果:OK! It is a test6.显示结果定向至文件echo "It is a test" > myfile7.原样输出字符串,不进行转义或取变量(用单引号)echo '$name\"'输出结果:$name\"8.显示命令执行结果  echo `date`结果将显示当前日期Thu Jul 24 10:08:46 CST 2014
0 0
原创粉丝点击