10

I have a bunch of commands in my zshrc which invoke another command in the background. The background command is an alias to a text-to-speech program (I use it to give me audio cues when processes like test suites and patches finish).

It currently gets invoked like this:

alert "Message for this current task" &

Pretty simple.

However, when I use this format, I get this output:

$ alert "Foobar" &
[1] 85072
$
[1]  + done       alert "Foobar"
$

I want to suppress the output of the pid and the done message. How do I do that?

I tried alert "Foobar" > /dev/null & but that only pipes the output of alert to devnull.

I tried alert "Foobar" & > /dev/null but that did unexpected bad things that I don't fully understand.

How do I use & in 'quiet' mode?

2 Answers 2

15

You can use a subshell to get rid of the job control messages:

$ alias alertme="xmessage Alert!"
$ ( alertme & )
$

If your commad also produces some output to STDOUT and/or STDERR, pipe those to /dev/null:

$ ( alertme > /dev/null 2>&1 & )
1
  • Thanks! I tried this, but I thought I needed to leave the & outside the (), so naturally it still gave me the output.
    – asfallows
    Aug 13, 2014 at 18:33
2

A slightly neater version of another answer here:

(&>/dev/null alertme &)
1
  • 1
    What's the difference between (&>/dev/null cmd &) and (cmd &>/dev/null &)? Dec 21, 2022 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .