Run .sh file from cygwin on windows 7

2019-08-17 05:12发布

问题:

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:

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