我正在尝试检查两个条件是否都返回预期值。
我想确保在继续之前返回预期值...
我有问题的一行是:if [ [ $ansmob = "y" ] || [ $flagbook != "1" ] ];
read -r -p "Would you like to add $site.booking.local as well? [y/n] " ansbook
if [ $ansbook = "y" ];
then sed "s/ServerAlias.*/& $site.booking.local/" -i $workdir/$site$dom.conf
flagbook="1"
fi
read -r -p "Would you like to add m.$site.booking.local? [y/n] " ansmob
if [ [ $ansmob = "y" ] || [ $flagbook != "1" ] ];
then sed "s/& $site.booking.local/& $site.booking.local m.$site.booking.local/" -i $workdir/$site$dom.conf
else
sed "s/ServerAlias.* /& m.$site.booking.local/" -i $workdir/$site$dom.conf
flagmobile="1"
fi
答案 0 :(得分:2)
替换
if [ [ $ansmob = "y" ] || [ $flagbook != "1" ] ];
与
if [ "$ansmob" = "y" ] || [ "$flagbook" != "1" ]
答案 1 :(得分:2)
使用bash的双括号,您可以使用&&
和||
if [[ $ansmob = "y" || $flagbook -ne 1 ]]
在双括号内,引用变量并不是绝对必要的:这个命令很聪明地评估带有空变量的表达式。
答案 2 :(得分:1)
二进制&& operator是AND操作的语法。