2012-11-03 100 views
2

我已經將此腳本編寫爲安裝postgres中的模塊,這是爲了向用戶顯示數據庫已創建並獲取他/她的輸入,因爲他們看到數據庫是創建。當我運行該腳本,我得到的錯誤line [:missing`]'請調試幫助

./dbtest: line 39: [: missing `]' 

我已經嘗試添加「」周圍是和'周圍是,我無法弄清楚什麼是失蹤。腳本如下

# 
# 
# Check to make sure the database was created and who is the owner 
# 
# 
if [ -f showdb ]; 

then 
     cp showdb /home 

else 
     echo " show database file is missing " 

fi 

if [ -f /home/showdb ]; 

then 
     su - postgres -c '/home/showdb' 

     echo " Do you see the data name created listed above? " 
     echo " " 
     echo " Type yes or no (type out the whole word please) " 
     echo " " 
     read dbawr 

      if [ $dbawr == yes && $dbawr == Yes ]; 

       then 

        echo "Great!" 
        exit 

       else 
        echo " Please contact tech support " 
        pause " Press [CTRL] [Z] to exit the program now " 
       fi 

    else 

     echo " File Missing!!" 

fi 

我在這個腳本中丟失了什麼?

謝謝!

回答

5

不能使用布爾型&&運算符,單個括號爲條件[ test = test ]。如果你正在使用bash(或類似的殼),首選的語法是使用雙括號:

[[ this == this && that == that ]] 

如果你擔心的便攜性,那麼你就應該堅持使用單支架,但使用它們像這樣:

[ this = this ] && [ that = that ] 

請注意,我沒有使用double equals(==)。這也不符合標準。

+0

但是,您可以使用'test'自己的邏輯選項。 '[this = this -a that = that]' – ghoti

+0

好的一點,並且一個嚴格的答案應該包括那個。但是,我(和[許多其他人](https://wiki.ubuntu.com/DashAsBinSh#A.5B))通常更傾向於將其視爲單獨的測試,而不是用'-a'和'-o'分隔開,特別是因爲測試變得更加複雜。 雖然不錯,但;) –