tags:

views:

45

answers:

4

I am trying to run a.out lot of times from command line, but am not able to start the processes in background because bash treats it as a syntax error.

for f in `seq 20`; do ./a.out&; done //incorrect syntax for bash near '&'

How can I place & on command line so that bash doesn't complain, and I am allowed to run these processes in background, so that I can generate load on the system.

P.S: I don't want to break it into multiple lines.

A: 

Break that into multiple lines or remove the ; after the &

Raghuram
+1  A: 

& is a command terminator as well as ; ; do not use both.

And use bash syntax instead of using seq, which is not available on all Unix systems.

for f in {1..20} ; do ./a.out& done
Benoit
+3  A: 

This works:

for f in `seq 20`; do ./a.out& done

& terminates a command just like ; or &&, ||, |.

This means that bash expects a command between & and ; but can't find one. Hence the error.

Aaron Digulla
Yikes - yet another reason to love zsh... ;-). Great job spotting that... though I guess once bitten it'd be hard to forget.
Tony
+1  A: 

Remove the ; after a.out:

for f in `seq 20`; do ./a.out& done
codaddict