我正在尝试制作一个 bash 脚本来提高我的技能。目标是让 bash 脚本打开另一个终端,启动浏览器,然后自行关闭它。
我可以做一切事情,但不能让它自己关闭。
#! /bin/bash
echo "type apps you want to launch"
read -r String
if [[ $String =~ "Brave" ]];
then gnome-terminal --window-with-profile=BashProfile -- nohup bash -c "sleep 1s; brave-browser &" && exit
fi
有人对我正在尝试做的事情有更好的解决方案吗?
我在命令后尝试 && exit 将其在引号内部和外部关闭,看看是否会关闭它。不过,启动后似乎没有命令运行,这是有道理的。
脚本中的
exit
仅退出包含命令的脚本,而不是启动脚本的终端。
我不确定你想杀死什么(初始终端或启动的终端),但尝试使用 kill -9 $$
来杀死父进程。代替
exit
(未经测试的代码)
#! /bin/bash
echo "type apps you want to launch"
read -r String
if [[ $String =~ "Brave" ]];
then gnome-terminal --window-with-profile=BashProfile -- nohup bash -c "sleep 1s; brave-browser &" && kill -9 $$
fi