bash 中有 goto 的等效项吗?下面是我正在编写的脚本的一小部分,根据用户输入,我想跳到下一段代码。
#!/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
# ...
关于linux - 在 bash 中跳过(转到)一段代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50344215/