如何實現返回頂層選單?

如何實現返回頂層選單?

我有一個複雜的菜單驅動程序,大致如下:

echo "Navigate through the following choices when you get the #? prompt: "
options=("Action 1" "Action 2" ...)
select $opt in "${options[@]}"
do
    case $opt in
        "Action 1")
            ./action1.sh 
            ;;
        "Action 2")
            ./action1.sh 
            ;;
        ...
    esac
done

(將其視為一個簡單的待辦事項清單應用程序,您可以在其中新增/刪除/編輯/查看待辦事項清單項目。因此,新增、刪除等就是操作)

其中一些action有點長,因此在操作進行到一半時,用戶可能會改變主意並希望返回主提示以嘗試其他操作。

我的問題是如何讓使用者回傳主提示?我希望有一個簡單的按鍵處理程序,可以讓用戶跳到select.有可能或有其他方法嗎?

答案1

您可以重新啟動主程式。

 # User wants to return to main
 exec main.sh

這將刪除您當前正在運行的腳本並將其替換為main.sh.

請注意,只有導出的變數在新啟動的main.sh.

相關內容