Credentials for mysql fail for mysqldump in bash script I am having a very strange problem in a script to back up MySQL schemas.  The script creates a list of schemas and then runs the mysqldump command for each of them. The credentials are stored in a separate file db_credentials.

The relevant lines of code are...

. /home/backupuser/db_credentials
user=$USERNAME
password=$PASSWORD
dbList=$(mysql -u$user -p$password -Bse "SHOW DATABASES")
for db in $dbList
do 
   mysqldump –u$user -p$password --single-transaction --routines  $db &gt; $dumpdir/${db}_${timestamp}.sql
   echo $db
done 


The output looks like this...

mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
db_1
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
db_2
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
db_3
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
...


This shows that the $dblist array variable is filled correctly, but for some reason, the myslqdump command is not using the credentials supplied. 

I am running the script from the command line using sudo, but I have no idea where it is getting user=root or the password from.

I just checked the backup directory, and the relevant files are being created, but they are empty.

MySQL version 5.1
O/S Centos 6.8
Bash version 4.1.2

Any help would be much appreciated
Apologies, I made a really amateurish error. Apparently, a few lines of code were at some point copied and pasted from a windows machine, so had CR/LF as the end-of-line character. 
Changed this to LF and it worked fine.

I would still be interested in why it decided to use root@localhost (and what password it was using), so feel free to comment here with an explanation.