1

In bash, I am trying to launch several xeyes at once.

If I do this:

for a in `seq 1 3`; do  "xeyes"; done

I get 1 xeye and the subsecuent xeyes comes up only when I close the previous xeye.

Therefore, I tried:

for a in `seq 1 3`; do  "xeyes &"; done

But on running this command, nothing happens.

What could I be doing wrong?

3 Answers 3

1

Usually starting X-enabled applications means they don't return control back to bash until they've finished, as you're seeing in the first example. In the second example, the quotations are (I think) starting a subprocess that doesn't know what display to run under.

Simply splitting it out to three lines (to avoid the necessity of quotes) did the trick for me. In other words:

for i in `seq 1 3`; do
 xeyes &
done 

Enjoy! This isn't the most useful demonstration of bash, but I suppose it could be entertaining.

1
  • 1
    When I did up arrow key, I found the 1 liner version of your 3 line code: "for i in seq 1 3; do xeyes & done"
    – bits
    Jul 19, 2010 at 21:27
2

Bash has a range operator and C-style for loops, so seq is usually not needed. You may need it in the Bourne shell or under some special circumstances. Here's how you'd do your example in pure Bash without calling any external programs (other than xeyes):

for a in {1..3}; do xeyes & done    # range of 1 to 3, no vars in this type of {}

or

for ((a = 1; a <= 3; a++)); do xeyes & done    # C-style for loop, can have vars
1
  • Thanks, I definitely would prefer these better styles of for loops.
    – bits
    Jul 19, 2010 at 22:12
0

Try

for a in `seq 1 3`; do xeyes & ; done

Your mistake is to put "xeyes &" in double-quotes. That makes bash treat it literally as a one-word command that contains a space and an ampersand.

2
  • With your command, I am getting "bash: syntax error near unexpected token `;'"
    – bits
    Jul 19, 2010 at 21:21
  • 1
    & plays the role of the semicolon, so you should omit the ;. Jul 19, 2010 at 21:39

You must log in to answer this question.

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