1

I have this bash script name test.sh and located in /tmp:

source $HOME/.backmeuprc
databases=`mysql -h$DBHOST -u$DBUSER -p$DBPASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

the .backmeuprc file is located in /home/user and has the following:

DBHOST="localhost"
DBUSER="mysqluser" #MySQL user that can dump all databases
DBPASSWORD="somepasswordwith!and$and+andotherspecialcaracters'"
DBPORT="3306"

and the issue is when the password has all the characters possible. How can I escape the $DBPASSWORD in this case? The issue is that the command is inside backticks. I have no experience in bash scripts but I've tried with "$DBPASSWORD" and with '$DBPASSWORD' and it doesn't work.

LATER EDIT: see the link of the script here, line 170 https://github.com/Ardakilic/backmeup/blob/master/backmeup.sh

  • 2
    What error message do you get when using "$DBPASSWORD"? (Or, if no error message, what information do you get about the failure?) – dhag Mar 6 '17 at 16:08
  • 1
    when I type in just the password it self in bash I get "event not found" but in this line of mysql I am getting "access denied for user ..." – Morpheus_ro Mar 6 '17 at 16:23
  • It would help if you could also clarify how it fails. On my tests, using double quotes makes it fail because MySQL doesn't recognize the password, for example. – terdon Mar 8 '17 at 10:56
  • @terdon Sorry, you are correct I took a call during my reply and just lost track! @Morpheus_ro when you just type password are you doing this backmeup -dbpass 'abc!edf' or backmeup -dbpass abc!edf The 2nd one fails with "can't find event" which is obvious, it's trying to find edf in history. – X Tian Mar 9 '17 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.