Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run two commands in a single line for loop in bash? [closed]

Tags:

bash

shell

Why can't I run two commands within a single line bash loop?

$ for i in {1..100} do printf %s "$(date)" ; mysql -uroot -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" ; sleep 10 ; done
-bash: syntax error near unexpected token `mysql'

But this simple version works:

for i in {1..3}; do echo $i ; ls ; done
like image 416
Ryan Avatar asked Mar 31 '16 17:03

Ryan


1 Answers

You need a ; after your brace expansion. You have it in the simple example, but not in the "broken" one:

for i in {1..100}; do printf %s "$(date)" ; mysql -uroot -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" ; sleep 10 ; done
                 ^ this one
like image 51
Eric Renouf Avatar answered Oct 28 '22 06:10

Eric Renouf