我对在 Ubuntu 上编程很陌生。我正在尝试做一个简单的 bash 脚本。
我有一个选择菜单工作,但我希望在其中做出的选择进入许多 if 语句,对应于所做的选择。
例如,这是伪代码:
Choose from the following
a)
b)
c)
a selected
if a is selected
then
run this script
fi
if b selected
then
run this script
fi
if c selected
then
run this script
Run Code Online (Sandbox Code Playgroud)
我如何将选择传递到相关的 if 语句中?
所有这些都必须从一个脚本运行。这可能很简单,但我对此很陌生,并且正在努力解决它。
你会使用一个case声明:
var=... your menu select code ...
case "$var" in
a )
script_a ;;
b )
script_b ;;
c )
script_c ;;
esac
Run Code Online (Sandbox Code Playgroud)