在不退出菜单的情况下从菜单中调用退出脚本

Win*_*ero 5 menu

我写了这个菜单,调用了几个脚本。这个脚本之一是

dbus-monitor --system
Run Code Online (Sandbox Code Playgroud)

所以它通过 dbus 显示实时流量。

但是当我想退出时,我通常会执行Ctrl+ C,但这也会退出我的菜单,我只想返回到我的菜单。

有没有我可以在 dbus-moniter 之后放置的代码,当检测到退出时,它会再次启动我的菜单?我的菜单只是另一个 .sh 脚本

或者 ....

- - - - - - - - 阐明 - - - - - - - -

我“还没有”那么高级;) 在脚本方面。这是我调用 dbus 脚本的菜单

select opt in "dbus Live Traffic" "option 2" "Main menu" "Quit"
    do
        case $opt in
            "dbus Live Traffic")
                curl -s -u lalala:hihihi ftp://ftp.somewhere.com/folder/dbuslivetraffic.sh | bash ;;   
            "option 2")
                do_something ;;   
            "Main menu")
                main_menu;;
            "Quit")
                quit_menu;;
        esac
        if [[ $opt != "Main menu" ]] || [[ $opt != "Quit" ]] ;
        then
            main_menu
        fi
    done
Run Code Online (Sandbox Code Playgroud)

这是我的 dbuslivetraffic.sh 的内容

dbus-monitor --system
Run Code Online (Sandbox Code Playgroud)

现在只有这一行,但也许在不久的将来会有更多的代码添加到这个脚本中。

我真的不明白我需要把TRAP@RoVo 建议的函数放在哪里

pLu*_*umo 7

您可以在子 shell 中运行该命令,并trapSIGINT运行时kill 0仅终止子 shell 的进程组。

select opt in a b; do
    case $REPLY in
      1)
        (
          trap "kill -SIGINT 0" SIGINT
          sleep 10
        )
        ;;
      2)
        sleep 10
        ;;
    esac
done
Run Code Online (Sandbox Code Playgroud)
  • 选择 (1) 将让您使用Ctrl+c而不会杀死菜单。
  • 选择 (2) 并按Ctrl+c也会取消菜单。