I have created a shell script that uses information stored in a config file. The issue I am facing is when I try to pass certain values stored in the config file, for use by the shell script, I get a syntax error.
For example:
config.conf
host=localhost
user=user
password=GhR6R3#h]dSq+C74)Jz9CDF6a7^&L[4= (not my real password)
db_name=database
script.sh
# Load config file TODO: make this more secure
source /path/to/config.conf
# MySQL database dump
mysqldump --lock-tables -h $host -u $user -p $password $db_name > dbbackup_`date +"%Y%m%d"`.bak
This is what happens when I attempt to run the script:
$ bash script.sh
Syntax error near unexpected token `)'
`password=GhR6R3#h]dSq+C74)Jz9CDF6a7^&L[4='
The issue seems to be related to certain characters used in my randomly generated password. I have tried wrapping $password
in quotes and when that didn't work I did the same with the actual password stored in the config file, but again I had no success.
What's the best way to solve this problem?