mysql command displays `-?` help instead of `-e` executing command when run from bash script (but not when run by hand)

100 Views Asked by At

I have a rather simple bash script.

#!/bin/bash
echo
echo What is the root statement for the new debate?
read body

echo
echo What is your mysql password?
read -s pass

echo
sql='INSERT
        INTO `Debate`   (`unblocked`,   `debaterId`,    `dirty` )
        VALUES          ('"'1'"',       '"'15'"',       '"'0'"' );
    INSERT
        INTO `Statement`    (`body`,            `debateId`,         `debaterId` )
        VALUES              ('"'"${body}"'"',   LAST_INSERT_ID(),   '"'15'"'    );'

#echo mysql -u resolution -p ${pass} -D resolution -e \"${sql//[^a-zA-Z0-9(),;\`\'_]/ }\"
mysql -u resolution -p ${pass} -D resolution -e \"${sql//[^a-zA-Z0-9(),;\`\'_]/ }\"

What this is meant to do should be pretty straight forward but it comes down to "ask user for input on terminal... form sql command with the provided input... insert into database in two tables." It's meant to be a quick hack for adding new debates into the database for testing while development is ongoing.

Instead, mysql prints the help as if I had used -?. No error... just the help text. Everything looks correct when the mysql command is echoed to the terminal. And if I copy and paste the echoed command it works just fine. I've searched google and stack overflow but found nothing about this.

U@H ~  mysql --version
mysql  Ver 15.1 Distrib 10.3.28-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
0

There are 0 best solutions below