我試圖檢查兩個條件是否返回預期值。 我想,以確保雙方繼續返回之前的預期值... 我的問題的路線是: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
你能告訴我一個使用例子嗎? –
你不能嵌套單個括號,只要'[[$ ansmob ==「y」|| $ flagbook!=「1」]]' – BroSlow
好吧,我知道,那麼正確的方法是什麼? –