本文介绍了[:在shell编程意外的运营商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code:

    #!/bin/sh
    #filename:choose.sh
    read choose
    [ "$choose" == "y" -o "$choose" == "Y" ] && echo "Yes" && exit 0
    [ "$choose" == "n" -o "$choose" == "N" ] && echo "No"  && exit 0
    echo "Wrong Input" && exit 0

但是,当我执行

    sh ./choose.sh

终端提示我,

   [: 4: n: :Unexpected operator
   [: 5: n: :Unexpected operator

有没有在我的bash脚本什么错误?
谢谢!

Is there any mistake in my bash script?Thanks!

推荐答案

有在您的庆典脚本没有错。但你和执行它的 SH 其中有一个可大可小的语法;)

There is no mistake in your bash script. But you are executing it with sh which has a less extensive syntax ;)

所以,运行庆典./choose.sh 来代替:)

这篇关于[:在shell编程意外的运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:16