Question: This seems like a pretty trivial thing to do, but I'm very stuck.

To execute something in the background, use `&`:

```
>>> sleep 5 &
[1] 21763
>>> #hit enter
[1]+  Done                    sleep 5

```

But having a bashrc-sourced background script output job information is pretty frustrating, so you can do [this](https://stackoverflow.com/questions/7686989/running-bash-commands-in-the-background-without-printing-job-and-process-ids) to fix it:

```
>>> (sleep 5 &)

```

OK, so now I want to get the PID of `sleep` for `wait` or `kill`. Unfortunately its running in a subshell so the typical `$!` method doesn't work:

```
>>> echo $!
21763
>>> (sleep 5 &)
>>> echo $!
21763 #hasn't changed

```

So I thought, maybe I could get the subshell to print its PID in this way:

```
>>> sleep 5 & echo $!
[1] 21803 #annoying job-start message (stderr)
21803 #from the echo

```

But now when I throw that in the subshell no matter how I try to capture stdout of the subshell, it appears to block until `sleep` has finished.

```
>>> pid=$(sleep 5 & echo $!)

```

**How can I run something in the background, get its PID and stop it from printing job information and "`Done`"?**

Answer: 
You can use `read` bulletin to capture output:

```
read -r pid < <(sleep 10 & echo $!)

```

Then:

```
ps -p $pid
  PID TTY           TIME CMD
78541 ttys001    0:00.00 sleep 10

```
I found a great way, no need sub-shell, will keep the parent-child relationship.
Since: `[1] 21763` and `[1]+ Done sleep 5` are all stderr, which is `&2`.
We can redirect `&2` to `/dev/null`, here is code:

```
exec 7>&2 2>/dev/null # Here backup 2 to 7, and redirect 2 to /dev/null
sleep 5
wait
exec 2>&7 7>&- # here restore 7 to 2, and delete 7.

```

See: [Using exec](http://www.tldp.org/LDP/abs/html/x17974.html)