我已将此脚本编写为安装postgres的模块,这是为了向用户显示数据库已创建并获取他/她的输入,因为他们看到数据库已创建.当我运行脚本时,我收到错误
./dbtest: line 39: [: missing `]'
Run Code Online (Sandbox Code Playgroud)
我试过在"是"和"是"周围添加"",我无法弄清楚缺少什么.脚本如下
#
#
# 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
Run Code Online (Sandbox Code Playgroud)
我在这个剧本中缺少什么?
谢谢!
您不能使用&&
带有单括号的布尔运算符条件[ test = test ]
.如果您正在使用bash(或类似的shell),首选语法是使用双括号:
[[ this == this && that == that ]]
Run Code Online (Sandbox Code Playgroud)
如果您担心可移植性,那么您应该坚持使用单个括号,但是如下所示使用它们:
[ this = this ] && [ that = that ]
Run Code Online (Sandbox Code Playgroud)
请注意,我没有使用double equals(==
).这也不符合posix标准.
归档时间: |
|
查看次数: |
6609 次 |
最近记录: |