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

If I run a command in the background with &, like this:

sleep 2 &

when the command finishes, I get "Done". How I can avoid seeing the "Done" message ?


Solution 1:

Run the command in a subshell:

(sleep 2 &)

Solution 2:

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".