shell脚本初学(echo使用)(四)

语法: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下

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值