Bash 具有多个提示和选项的shell脚本
我正在编写一个脚本来自动化Linux内核构建过程。在我的脚本中,我有一些提示,有些是/否,有些是特定的操作。以下是我的问题: 如何在函数运行后正确关闭函数并转到下一个选项? 如何跳转到指定的操作并跳过其间的提示/操作? 以下是一个例子:Bash 具有多个提示和选项的shell脚本,bash,shell,sh,Bash,Shell,Sh,我正在编写一个脚本来自动化Linux内核构建过程。在我的脚本中,我有一些提示,有些是/否,有些是特定的操作。以下是我的问题: 如何在函数运行后正确关闭函数并转到下一个选项? 如何跳转到指定的操作并跳过其间的提示/操作? 以下是一个例子: #!/bin/bash echo "Do you need to install the necessary compiling tools?" select yn in "Yes" "No"; do case $yn in Yes )
#!/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
#/bin/bash
echo“是否需要安装必要的编译工具?”
在“是”“否”中选择yn;做
案件$yn
是)sudo apt获取安装工具;打破
否)
以撒
echo“您需要eidt您的配置吗?”
在“否”中选择“是”;做
每箱$ny
否)呃
或者更好的方法是,将每个部分放入一个函数中,并根据需要调用它们。您的意思是类似于make oldconfig
?或者makemenuconfig
?使用第一个case语句作为其余语句的模型,并消除对no选项的处理。然后,您的脚本将“通过”到下一个案例块,在该案例块中应用相同的想法。祝你们好运,谢谢你们。这是最好的答案:使用您的第一个case语句作为其余语句的模型,并消除对no选项的处理。然后,您的脚本将“通过”到下一个案例块,在该案例块中应用相同的想法。祝你好运谢尔特。。。它唤起了我的记忆,使我想起了如何做我想做的事。稍后我会将我的脚本发布给其他人看。因为我是一个新用户,8个小时内我无法回答自己的问题…哈哈
echo "Do you need to eidt your configuration?"
select ny in "No" "Yes"; do
case $ny in
No ) break;;
Yes )
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;
...
break;;
esac