7

How do you make the escaping work so that the & is actually running the first command in the background?

# foo param1 param2 >> run.out &; tail -f run.out
Paul Tarjan
  • 559
  • 3
  • 8
  • 17

4 Answers4

16

Just drop the semicolon:

# foo param1 param2 >> run.out & tail -f run.out
katriel
  • 4,407
  • 22
  • 20
  • 7
    It helps to think of the ampersand as a *variant* of the semicolon, which it is, really. – Teddy Oct 07 '09 at 04:52
1

You need to put the backgrounded command in ()'s.

(ls -R / >>/tmp/list & ); tail -f /tmp/list

Sadly, this really backgrounds it. You won't be able to us %1 to get to its PID.

TomOnTime
  • 7,567
  • 6
  • 28
  • 51
0

I just ran into this question as well, and solved it this way:

`foo param1 param2 >> run.out &` ; tail -f run.out

I don't know if the semantics are different.

For this specific case, the following is also useful:

foo param1 param2 | tee -a run.out
Steve Bennett
  • 5,539
  • 12
  • 45
  • 57
0

You could use nohup:

nohup cmd & 

tail -f nohup.out
Stephan
  • 51
  • 1
  • 2