17
[USER@SERVER ~] sleep 3 &
[1] 5232
[USER@SERVER ~] 
[1]+  Done                    sleep 3
[USER@SERVER ~] 

How do I /dev/null these two messages?:

[1] 5232
[1]+  Done                    sleep 3

p.s.: so I need the output of the process, but not the mentioned two lines!

  • You only get those lines when you run it interactively. You don't if you run it from a script, for example. – derobert Jan 25 '13 at 0:25
23

It's not the program output, it's some useful shell information.

Anyway, those can be hided by using subshell and output redirection

( sleep 3 & ) > /dev/null 2>&1
  • 2
    "2>/dev/null" is the good thing, i need the output from the process – LanceBaynes Dec 10 '11 at 12:36
  • @LanceBaynes The process could also write something on stderr. – Chris Down Dec 10 '11 at 18:45
  • 2
    It's unfortunate that this defeats the retrieval of pid with $! – Deleplace Jun 8 '16 at 14:08
3

In bash or zsh, you can call disown %1 to tell the shell to forget about the job. Then the shell won't print any message about that job, nor will it show it when you run jobs or ever send a SIGHUP to it. In zsh, starting the job with &! instead of & is equivalent to calling disown on it immediately.

0

Can't comment (yet) on @Gilles but it seems that & disown also works in bash:

sleep 3 & disown
  • This doesn't seem to work in Bash v.4.1.2 – Alexej Magura Jan 13 '17 at 16:16
0

Try:

user@host:~$ read < <( sleep 10 & echo $! )
user@host:~$ echo $REPLY
28677

And you have hidden both the output and the PID. Note that you can still retrieve the PID from $REPLY

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.