2

我已经将此脚本编写为安装 postgres 的模块,这是为了向用户显示数据库已创建并获取他/她的输入,以便他们看到数据库已创建。当我运行脚本时,我得到了错误

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

我尝试在 yes 周围添加“”,在 yes 周围添加 '',但我无法弄清楚缺少什么。脚本如下

#   
#
# 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

我在这个脚本中缺少什么?

谢谢!

4

1 回答 1

6

您不能使用&&带有单括号条件的布尔运算符[ test = test ]。如果您使用 bash(或类似的 shell),首选语法是使用双括号:

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

如果你担心可移植性,那么你应该坚持使用单括号,但像这样使用它们:

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

请注意,我没有使用双等号 ( ==)。这也不符合posix。

于 2012-11-03T13:46:23.047 回答