Variable in bash script not working as expected

I have this script:

sudo mysqldump -c -u username -p1234 dbname > $VAR


But if I run this script, I get this error:

: Protocol error 3: mysql-export.sh: cannot create eric.sql


But if I don't use this variable, but only this:

sudo mysqldump -c -u username -p1234 dbname > eric.sql


... it works well. What am I wrong?


source to share

2 answers

The problem was that the script had Windows style line breaks (I used notepad). After i used Nano write a script, it solved it.

Thanks for answers!




may change the $ PATH variable, depends on your security policy.

   -E  The -E (preserve environment) option will override the env_reset
       option in sudoers(5)).  It is only available when either the match-
       ing command has the SETENV tag or the setenv option is set in sudo-


You can add the full path to the file or remove it sudo

in your script. This should work as well:

 sudo PATH="$PATH" mysqldump -c -u username -p1234 dbname > $VAR




All Articles