【发布时间】:2012-08-08 08:00:59
【问题描述】:
我正在尝试创建一个脚本以使用 shell 自动从数据库中删除所有表。
注释掉的变量 $drop 工作正常,但是当我尝试在表中替换时
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
【问题讨论】:
-
打开 shell 调试以查看 $command 使用了哪些值等。在循环之前添加
set -vx。要关闭,您可以使用set +vx。祝你好运。 -
你好,我用这个得到了这些结果:
+ for table in '$tables' + set -vx + command=''\''drop table property_thumbnail'\''' + for table in '$tables'@shellter