construct a sql , assign it to a variable and execute inside shell script I am trying to execute a mysql query inside my shell script, which is not executing .
Here is what i am trying to do

query="\"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';\""


echo $query

"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';"


Inside my shell script , i am executing below which is not working. It is not giving any error but simply not considering -e option and listing down all the valid options for mysql client.

mysql -u$username -p$password -e$query


I even validated below in my shell prompt

echo "mysql -uroot -p -e$query"
mysql -uroot -p -e"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';"


which is perfectly fine and executes without any issues. I am not sure what to do now. please help.Thanks
You need to do it like this:

query="select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB'"
mysql -uroot -p -e"${query}"


or

query="select count(*) from information_schema.tables"
query="${query} where TABLE_SCHEMA not in"
query="${query} ('mysql','performance_schema','information_schema')"
query="${query} and engine!='INNODB'"
mysql -uroot -p -e"${query}"


Double quotes do not need to be part of the query variable