跳过(转到)bash中的一段代码?



在 bash 中是否有等价物可以转到?下面是我正在处理的脚本的一小部分,根据用户输入,我想跳到下一段代码。

#!/bin/bash
WAN1_prompt
read -p "WAN1 exists?: " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
Skip to WAN1
else
Skip to WAN2_prompt
fi

WAN1
read -p "Enter WAN1 IP: " wan1
if [[ $wan1 =~ ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
sed -i~ -e "s/bizip/$wan1/g" test.txt
else
echo Error
fi

WAN2_prompt
read -p "WAN2 exists?: " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
Skip to WAN2
else
exit
fi
read -p "Enter WAN2 IP: " wan2
if [[ $wan2 =~ ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
sed -i~ -e "s/bizip/$wan2/g" test.txt
else
echo Error
fi

不,没有。

但此示例不需要它:

read -p "WAN1 exists?: " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
# WAN1
read -p "Enter WAN1 IP: " wan1
if [[ $wan1 =~ ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
sed -i~ -e "s/bizip/$wan1/g" test.txt
else
echo Error
fi
fi
# WAN2_prompt
read -p "WAN2 exists?: " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Enter WAN2 IP: " wan2
if [[ $wan2 =~ ^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
sed -i~ -e "s/bizip/$wan2/g" test.txt
else
echo Error
fi
fi
# ...

最新更新