想请教您的意见。
我正在使用 while true、read 和 case 构建带有嵌套循环的交互式 bash 脚本。我的问题是,在第二个内循环之后(选择“循环 1.3”时)我想用另一个内循环继续脚本,但它失败了(部分是我关于失败的评论)。
我假设我在语法上遗漏了一些东西,但找不到......
下面是脚本的代码。提前致谢。
#!/bin/bash
while true; do
read -rep $'Loop #1 (outerloop)? \n\tYES\tNO\n\n' yn
case $yn in
[Yy]* )
while true; do
read -rep $'Loop #1.2 (first inner loop)? Please, choose variant 1 or 2.\n\t1\t2\n\n' yn
case $yn in
[1]* )
while true; do
read -rep $'Loop #1.3 (second inner loop)?\n\tYES\tNO\n\n' yn
case $yn in
[Yy]* ) read -rep $'Loop #1.3. Variant Yes.:\n\n' LOOP3Q1; break 3;;
[Nn]* ) break 3;;
esac
done; break 3;;
[2]* )
while true; do
read -rep $'Loop #1.3 (second inner loop).\n\tYES\tNO\n\n' yn
case $yn in
[Yy]* ) read -rep $'Loop #1.3 variant Yes.\n\n' LOOP3Q2; break 3;;
[Nn]* ) break 3;;
esac
done; break 3;;
# Here it failes. If here I break all loops - it works, but I need to continue...
echo "Continue loop 1.2 (first inner loop)"
while true; do
read -rep $'Loop #1.3 (second inner loop).\n\tYES\tNO\n\n' yn
case $yn in
[Yy]* ) read -rep $'Loop #1.3 variant Yes.\n\n' LOOP3Q2; break 3;;
[Nn]* ) break 3;;
esac
done; break 3;
esac
done; break 2;;
Nn]* ) break;;
esac
done