我写了这个菜单,调用了几个脚本。该脚本之一是
dbus-monitor --system
因此它显示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
这是我的dbuslivetraffic.sh的内容
dbus-monitor --system
目前仅是这一行,但也许在不久的将来会将更多代码添加到该脚本中。
我真的不明白我需要把TRAP
@RoVo建议的功能放在哪里
您可以在子Shell中运行该命令,并trap
在SIGINT
运行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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句