gpt4 book ai didi

linux - [ :Unexpected operator in shell programming

转载 作者:IT老高 更新时间:2023-10-28 12:21:15 39 4
gpt4 key购买 nike

我的代码:

    #!/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 脚本有什么错误吗?谢谢!

最佳答案

您的 bash 脚本没有错误。但是您使用 sh 执行它,它的语法不太广泛;)

所以,改为运行 bash ./choose.sh :)

关于linux - [ :Unexpected operator in shell programming,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3411048/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com