关于linux中,在使用script脚本时,老是提示“ [ ” unexpected operator 的问题!

在学习linux script脚本程序的编写时,脚本程序如下所示:

  1 #!/bin/bash
  2 #Program
  3 #   This program output "Hello world"
  4 #History 
  5 # 2017.9.20     liuqiqi     First release
  6 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  7 export PATH
  8 if [ "$#" == 0 ] ; then
  9    echo "You must input parameters!" 
 10    exit 0
 11 elif [ "$1" == "Hello" ] ; then
 12    echo "Hello,how are you?"
 13    exit 0
 14 else
 15    echo "The only parameter you can input is Hello!"
 16    exit 0
 17 fi


一直出现一个问题就是

sh09.sh : 8: [ : 0: unexpected operator

sh09.sh: 11: [ : unexpected operator

改了好长时间都没改好!后来上网查找之后才发现linux默认的操作环境是dash,而我需要用bash环境才能编译,而我一直使用的是sh sh09.sh(sh09.sh是脚本程序的名字)

改成bash sh09.sh就好了!

在鸟哥的私房菜中说用bash或者sh执行都可以,实际上我们编写的shell是bash,之所以可以用sh,是因为/bin/sh是个连接文件,连接到/bin/bash,所以执行sh时,其实
就是执行bash,但是在ubuntu版本中,/bin/sh默认连接到/bin/dash,所以执行sh,其实是执行dash,所以会出错!
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值