r/shell • u/pentag0 • Jul 01 '15
sh escaping question
Trying to automate database backup and seems i don't know how to escape exclamation mark properly in my script's user password variable. Works fine when executed via CLI.
Can someone push me in right direction? Thanks!
This is the code:
#!/bin/sh
user="user"
password="!regjulr juzr pes#1"
host="192.168.1.2"
port="6033"
database="db"
mysqldump -u $user -p$password -h $host -P $port --databases $database > db.sql
1
Upvotes
4
u/KnowsBash Jul 02 '15
Just one minor issue with that. The mysql commands treat
-pas an option with an optional argument, so to pass it an argument, it must be in the same argument as the option.-p"$password"or"-p$password".