2013-05-15 45 views
1

每當我嘗試運行我的shell腳本時,如果測試中出現4個不同的錯誤,當條件測試時拒絕Shell腳本權限

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 

任何想法,爲什麼我可能會得到這個錯誤信息,它是什麼意思?

+0

無法重現。我猜想你的訪問資源的權限被拒絕了。很難多說,只給出僞碼。 – DevSolar

+0

你在運行什麼外殼? – choroba

+0

@choroba#!/ bin/sh –

回答

5

括號運行一個子shell。使用括號進行比較:

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

我的確如你所說,而我知道得到的錯誤信息./script:45 [:意外的操作符代替以上每行的錯誤 –

+1

@nkon:OK ,使用單個'='。 – choroba

+0

作品!但爲什麼?我以爲單個=將變量設置爲一個值? –

相關問題