0

I'm trying to write a bash script to automate some MySQL backups and I'm using mysqlshow to test whether I've got a successful connection. Its working, but the problem is that some of my MySQL passwords contain spaces and the scripts are choking on passwords that contain spaces.

If I define a variable

mysqlshow="mysqlshow -u $user -p'$password' database_name"

Then try run that command with

result=$($mysqlshow)

I get an error from mysqlshow saying Too many arguments. This is being caused by spaces in $password as it works for passwords without spaces.

Dom
  • 2,980
  • 2
  • 28
  • 41
  • Define `mysqlshow=(mysqlshow -u "$user" -p"'"$password"'" database_name)` and do `result="${mysqlshow[@]}"` – Inian Aug 21 '23 at 13:11
  • And quote the variable `result`, when printing, `echo "$result"` – Inian Aug 21 '23 at 13:16
  • 1
    See: [Why does shell ignore quoting characters in arguments passed to it through variables?](https://stackoverflow.com/questions/12136948/why-does-shell-ignore-quoting-characters-in-arguments-passed-to-it-through-varia) – tjm3772 Aug 21 '23 at 14:25

0 Answers0