每当我尝试运行我的 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/