我已将此脚本编写为安装postgres的模块,这是为了向用户显示数据库已创建并获取他/她的输入,因为他们看到数据库已创建。当我运行脚本时,我收到错误
./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
我在这个剧本中缺少什么?
谢谢!
答案 0 :(得分:5)
您不能将布尔&&
运算符与单括号条件[ test = test ]
一起使用。如果您正在使用bash(或类似的shell),首选语法是使用双括号:
[[ this == this && that == that ]]
如果您担心可移植性,那么您应该坚持使用单个括号,但是如下所示使用它们:
[ this = this ] && [ that = that ]
请注意,我没有使用双等号(==
)。这也不符合posix。