I have a following line in my shell script.
time mysqlshow -u$user -p$password | egrep -v 'information_schema|performance_schema' | awk '{print "mysql -u$user -p$password -Bse \"drop database", $2, "\""}'
The first $user is correctly changing to username variable. But the one within awk statement does not. I tried to add double and single quotes with and without escape characters \ but it does not work.
You need to make sure that
$userand$passwordare surrounded by double quotes (") or by nothing and, as @jkerian mentioned, that$2is surrounded by single quotes (') or, if it is in double quotes, preceded by a backslash to make\$2.Try this (this is the cleaner one in my opinion):
Or this:
Or this:
It’s a mess, I know. But it should work.