2

I'm new in Linux and I also know this is a pretty common problem in the forum's questions but I have tried several options and I can't solve this issue. I am trying to execute the following script:

!/bin/bash
for i in {1..10}
do 
    asreml -r2 Prueba_"$i".as > stdout_"$i".txt &&
done

But I got the following error message:

bash: ./jobs1-2.sh: line 9: syntax error near unexpected token `done'
bash: ./jobs1-2.sh: line 9: `done'

I will appreciate any help

Thomas
  • 6,242
  • 8
  • 26
  • 32
Fersal
  • 67
  • 5

1 Answers1

4

Indeed, as the commenters have shown, you have a syntax error inside the loop, which confused bash when it tried to find the end of the loop.

You probably meant to either:

  • chain a second command after asreml that would run if asreml finished successfully ($? == 0); for example: asreml -r2 Prueba_"$i".as > stdout_"$i".txt && echo asreml finished successfully or

  • put the asreml command into the background: asreml -r2 Prueba_"$i".as > stdout_"$i".txt &

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • Thank you very much for your answer, and also appreciate to the commenters. Actually the problem was the two &&, the only way as it worked was replacing them by ";" as glen jackman said, ASReml uses && to connect tow commands. What I don't know is if ASReml will start the next job even if the previous one fails. – Fersal Mar 04 '17 at 17:19
  • @Fersal you don't need `;` either. And yes, this will start the next even if the previous one fails. If you don't want that, use `asreml -r2 . . . || exit`. But this should be in a new question. Also, since Jeff answered your question, please take a moment and [accept it](http://unix.stackexchange.com/help/someone-answers) by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. – terdon Mar 04 '17 at 17:21
  • @Fersal, see [terdon's excellent explanation of the various control operators](http://unix.stackexchange.com/questions/159513/what-are-the-shells-control-and-redirection-operators/159514#159514) such as `&&` and `||` to decide when to execute a second command based on the success of the first one. – Jeff Schaller Mar 04 '17 at 17:44
  • OK, actually my problem came back, now when I submit script with more jobs they do not work. I have tried this, but it still doesn't works. – Fersal Mar 04 '17 at 20:27
  • #!/bin/bash for i in {1..10} do asreml -r2 Prueba_"$i".as > Stdouts/stdout_"$i".txt || exit; done – Fersal Mar 04 '17 at 20:30
  • As terdon said, if you have a new/ different problem, ask a new question. Link to this one if you think it would help. – Jeff Schaller Mar 04 '17 at 20:36