我正在编写一个脚本来自动化 Linux 内核构建过程。在我的脚本中,我有提示,有些是/否,有些是特定的操作。这是我的问题:如何正确关闭函数并在该函数运行后移至下一个选项?如何跳转到指定的操作并绕过其间的提示/操作?这是一个例子:
#!/bin/bash
echo "Do you need to install the necessary compiling tools?"
select yn in "Yes" "No"; do
case $yn in
Yes ) sudo apt-get install tools; break;;
No ) <Here I want to skip to the next step. I originally left it
blank and removed the "done" command (after esac command)
to do this, but if I choose yes, it skips to the end
(where the next "done" command is and ends the script>
esac
<I had to flip the yes/no for the script to skip to the next prompt>
echo "Do you need to eidt your configuration?"
select ny in "No" "Yes"; do
case $ny in
No ) <what do I put here to skip to the next tag
(labeled compile for example purposes); break;;
Yes )
esac
echo "You have 3 options with how you can edit you config file."
select yn in "Gtk" "KDE" "Terminal"; do
case $yn in
Gtk ) make gconfig; break;;
KDE ) make xconfig; break;;
Terminal ) make menuconfig; break;;
esac
done
done
done <I had to insert all these "done" to end the file, but
the scripts doesn't work the way I want it to...>
echo "Are you ready to compile"
select yn in "Yes" "No"; do
case $yn in
Yes ) make; break;;
No ) exit;;
esac
done
所以基本上脚本是分阶段运行的。1. 是否需要安装工具 - 如果是,安装它们并进行下一步 - 如果没有,进行下一步 2. 是否要编辑配置文件 - 如果是,如何;- opt1 - opt2 - opt3 -然后,完成后,跳到下一步 -如果没有,则跳到下一步 3.编译