Run .sh file from cygwin on windows 7

2019-08-17 05:04发布

I am trying to run .sh file from cygwin on windows 7

My dumdb.sh file content

#!/bin/bash
for database in $(mysql -e "show databases"|awk -F " " '{print $1}') do
    mysqldump -u root -h localhost -p $database > $database.sql
done

On running this command

$ sh dumpdb.sh

m getting following error

bash: line 3: syntax error near unexpected token `mysqldump'
bash: line 3: `mysqldump $database > $database.sql'

Where I am doing wrong?

1条回答
爷、活的狠高调
2楼-- · 2019-08-17 05:29

You are missing a ; before do:

#!/bin/bash
for database in $(mysql -e "show databases"|awk -F " " '{print $1}') ; do
    mysqldump $database > $database.sql
done
查看更多
登录 后发表回答