Question: here is the command:

```
 # ls >log 2>&1 &
 [1] 24274

```

now I want this line `[1] 24274` to redirect a another file. any ideas?

Answer: 
[Use `$!`:](http://www.gnu.org/software/bash/manual/bashref.html#Special-Parameters)

```
ls >log 2>&1 &
echo ls: pid=$!

```
Unless you're trying to get the job number, the easiest way to do this is to use *$!*, which will give you the PID of the most recent background job. For example:

```
$ sleep 30 & bg_pid=$!; echo $bg_pid
[2] 10100
10100

```

If you really want to get the job number back from the stored PID, perhaps to use Bash's job control instead of sending signals to the process with *kill*, you can do this:

```
jobs -l | fgrep $! | perl -ne 'print "$1\n" if /\[(\d+)\]/'

```