Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer
    
That worked thanks! –  bits Jul 19 '10 at 21:27
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 '10 at 21:27
    
Oooh, thanks for the note. –  Jeff McJunkin Jul 19 '10 at 21:28

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
share|improve this answer
    
Thanks, I definitely would prefer these better styles of for loops. –  bits Jul 19 '10 at 22:12

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.

share|improve this answer
    
With your command, I am getting "bash: syntax error near unexpected token `;'" –  bits Jul 19 '10 at 21:21
1  
& plays the role of the semicolon, so you should omit the ;. –  Dennis Williamson Jul 19 '10 at 21:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.