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

来源:互联网 发布:剑三万花成女捏脸数据 编辑:程序博客网 时间:2024/05/20 16:11
在学习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 operatorsh09.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,所以会出错!
阅读全文
0 0
原创粉丝点击