linux - 条件测试时 Shell 脚本权限被拒绝

标签 linux shell unix

每当我尝试运行我的 shell 脚本时,我都会在 4 个不同的 if 测试下收到错误。

script.sh 45: script.sh: : Permission denied
script.sh 52: script.sh: : Permission denied
script.sh 59: script.sh: : Permission denied
script.sh 324: script.sh: : Permission denied

我在我的脚本上做了一个 chmod 777,所以每个人都有权限。脚本是这样运行的:

./script fileToUse

下面是给出错误信息的那几行:

if ( "$VAR" == "Condition_1" )
then
    do stuff
elif ( "$VAR" == "Condition_2" )
then 
    do stuff
elif ( "$VAR" == "Condition_3" )
then 
    do stuff
else
    do stuff
fi

324 行看起来是这样的:

if ( "$flagIsSet" -eq 0 )
then
    do stuff
fi

知道为什么我会收到此错误消息及其含义吗?

最佳答案

括号运行一个子shell。使用括号进行比较:

if [ "$VAR1" = "Condition_1" ] ; then
    # do stuff
fi

关于linux - 条件测试时 Shell 脚本权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16570587/

相关文章:

python - 同步两个不同的进程同时开始

shell - uniq -u 与特定列

linux - 如何在 Azure Linux Web 应用程序上托管 Angular

linux - 在 Perl 中连接变量

linux - RedHat 中的手指信息从何而来?

c - C中访问并运行/usr/bin程序

linux - "while (sleep 100 &!) do; done"在 zsh 中如何工作,它如何在 bash 中复制?

html - 通过 html 按钮(onclick)执行 shell 命令

linux - 从 shell 向 CloudWatch 发送事件

unix - chalice war java.sql.SQLException : Io exception: Invalid number format for port number