![从文件中选择菜单选项 --shell 脚本](https://linux22.com/image/220834/%E4%BB%8E%E6%96%87%E4%BB%B6%E4%B8%AD%E9%80%89%E6%8B%A9%E8%8F%9C%E5%8D%95%E9%80%89%E9%A1%B9%20--shell%20%E8%84%9A%E6%9C%AC.png)
我有一个关于 shell 脚本中菜单的问题。我在 shell 脚本中创建了一个菜单。但是,在其中一个选项中,我有一个用户可以从中选择的列表,但该列表很大,所以我希望用户从文件中选择该选项。我们该怎么做?
:select_menu
cls
echo.
echo ====================
echo Main Menu
echo ====================
echo 1 =Airport
echo 2 =Warhouse
echo 3 =Parcel
echo 4 =Other Projects
echo ------------------------------------------------------
echo q = Quit
echo -------------------------------------------------------
set /p op="Select option:"
if "%op%"=="1" goto op1
if "%op%"=="2" goto op2
if "%op%"=="3" goto op3
if "%op%"=="4" goto op4
if "%op%"=="q" exit
:op1
color 17
cls
echo.
echo ====================
echo Airport Menu
echo ====================
echo 1 =Gotenburge
echo 2 =Heathrow
echo 3 =Brussels
echo 4 =Kiev
echo ------------------------------------------------------
echo r = Return to Main Menu
echo -------------------------------------------------------
set /p a_op="Select airport:"
if "%a_op%"=="1" echo "Contact A.N.OTher" && pause
if "%a_op%"=="2" echo "Contact B.N.OTher" && pause
if "%a_op%"=="3" echo "Contact B.N.OTher" && pause
if "%a_op%"=="4" echo "Contact C.N.OTher" && pause
if "%a_op%"=="r" goto select_menu
goto op1
:op2
echo you selected Warhouse
color 0a
pause
cls
goto begin
goto :eof
:op3
echo you selected Parcel
color fc
pause
cls
goto begin
:op4
echo you selected Other Projects
color a1
pause
cls
goto begin
:exit
在机场菜单中,我有 250 个机场作为示例,但我不想列出所有机场,我希望用户能够检查名为 Airport_list 的单独文件,然后选择相关选项。