I’m trying to create a script to automatically delete all of the tables from a database using shell.
The commented out variable $drop works fine, however when I try to substitute in the table
for table in $tables
do
command="'drop table ${table}'"
# drop=$(${login} -e 'drop table test') -- this works fine
drop=$(${login} -e $command)
echo $drop
# echo -e "Removed table ${table}"
done
(major edit)
The issue is with your use of quotes. In your code, since you do not quote
$commandit is subject to word splitting by the shell. The $login command receives these arguments:"-e", "'drop", "table", "table_name'"— note the stray single quotes in the second and last elements.Do this: