前言
Shell Script也能做出上下選單
function
基本上這個功能是利用function功能刻出來的,我也是找到後複製修改而已
function code
參考資料
shell - Arrow key/Enter menu - Unix & Linux Stack Exchange
select_option
1 |
|
select_opt - 更容易在case中使用
1 | function select_opt { |
應用方法
select_option用法
code
1 | ... |
效果
1 | Select one option using up/down keys and enter to confirm: |
select_opt
Code
1 | ... |
效果
1 | [selected Yes] |
利用ls/cat等指令搭配select_opt製作選單
舉例:選擇目錄A,B,C作為選單
前提:目錄A,B,C的名字是會變動的(Eg:自動依照日期備份後會建立日期目錄)
1 | [kiwi]$> ls /storage/backup |
已知預設我的script會移除超過5天的備份, 所以可以假設最大的目錄數量為5
1 | # 在script中建立變數 |
效果
1 | [2025-03-24] |
設定的範圍大於實際目錄的數字的時候會有空白的選項