Preventing bash from displaying "Done" when a background command finishes executing

Execute the shell built-in:

$ set +m

This works by turning off "monitor mode" so the shell doesn't report terminating background jobs.

Although running the command in a subshell like:

$ (sleep 2&)

...will also disable the message, the only reason it works is because monitor mode is enabled by default only for interactive shells. That is, the subshell avoid the message by running an extra shell that has an automatic "set +m".


Run the command in a subshell:

(sleep 2 &)

I'd like to clarify the two earlier answers. If what you want is never to see the Done message from any commands in your shell, set +m is the way to go. Just put it in your .profile and/or .bashrc and be done. Note however, that if you type this:

set +m
sleep 2 &
set -m

and the sleep ends after the final set -m, you will still get the done message.

If you want to disable the message for a single command invocation, the subshell technique (sleep 2 &) is the way to go.

In all honesty, I only knew about set +m, so +1 to Wooble for enlightening me. However, it is worth noting that which of the two solutions you want depends on what you are trying to do.

Tags:

Bash