How do I include a string with an expression in a command in a bash script?
Consider the following:
#!/bin/bash
exclusions='Database|information_schema|mysql'
echo "mysql -e 'SHOW DATABASES' | grep -E -v '$exclusions' > outfile"
mysql -e 'SHOW DATABASES' | grep -E -v '$exclusions' > outfile
The script prints to the screen:
mysql -e 'SHOW DATABASES' | grep -E -v 'Database|information_schema|mysql' > outfile
... so I think my syntax is producing the command string I want. And when I manually enter the printed string at the command line, the command puts all database names, except those in the grep expression, into 'outfile'.
But the script exports all database names, without excluding those in the grep expression, to the file. Why is the script overlooking the grep expression?