我正在尝试检查这两个条件是否都返回预期值。我想确保在继续之前两者都返回预期值......我有问题的台词是: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
替换
if [ [ $ansmob = "y" ] || [ $flagbook != "1" ] ];
跟
if [ "$ansmob" = "y" ] || [ "$flagbook" != "1" ]
使用 Bash 的双括号,您可以使用 &&
和 ||
if [[ $ansmob = "y" || $flagbook -ne 1 ]]
在双括号内,并非绝对需要引用变量:此命令在计算具有空变量的表达式时很聪明。
二进制&&运算符是AND操作的语法。