我正在使用Ubuntu上的bash。我想要一个shell脚本来启动一个程序,并且继续执行下一行,即使该程序尚未终止。
(my-long-running-process &)
,可以将脚本作为单独的进程在后台运行。您必须将该进程在后台运行,但是您必须先启用作业控制。否则,如果需要,请无法终止或将该进程带到前台。
要启用作业控制,请执行以下操作:
set -m
task &
要操作后台任务,请使用jobspec语法(%[n]
)。例如,要杀死最后启动的进程,请执行:
kill %
bash
的手册在JOB CONTROL章节中提供了更多信息。&
将命令放在后台运行,但仍然在这里查看,可能是因为你的终端在脚本执行后没有再次打印提示符。或者更准确地说,它打印了提示符,但是你启动的应用程序在终端中输出了一些内容。
例如,这个脚本。#!/usr/bin/bash
firefox --new-instance -P Something &
#!/usr/bin/bash
set -m
firefox --new-instance -P Something &
laurent@laurent-GL73-8SD:~/redacted$ ./fire.sh
laurent@laurent-GL73-8SD:~/redacted$ Gtk-Message: 22:35:26.454: Not loading module "atk-bridge": The functionality is provided by GTK natively. Please try to not load it.
(firefox:47696): Gtk-WARNING **: 22:35:26.571: GTK+ module /snap/firefox/3289/gnome-platform/usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so cannot be loaded.
GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.
Gtk-Message: 22:35:26.571: Failed to load module "canberra-gtk-module"
(firefox:47696): Gtk-WARNING **: 22:35:26.573: GTK+ module /snap/firefox/3289/gnome-platform/usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so cannot be loaded.
GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.
Gtk-Message: 22:35:26.573: Failed to load module "canberra-gtk-module"
ATTENTION: default value of option mesa_glthread overridden by environment.
ATTENTION: default value of option mesa_glthread overridden by environment.