我在bash脚本中构建了一个mysql命令。但是在这个脚本中,mysql命令不起作用;控制台显示mysql默认帮助输出(因为它是使用“--help”参数调用的)。我的错是什么?
这是脚本:
declare mysql=/usr/bin/mysql
declare data=("ALTER TABLE ...", "ALTER TABLE ...")
declare args=""
declare dbName="testdb"
# In original version the following are received as parameter
declare live=true
declare mysqlArgs="-u root"
for i in "${data[@]}"; do
args="START TRANSACTION; $i;"
if [ "$live" = true ] ; then
cmd="$cmd COMMIT;"
else
cmd="$cmd ROLLBACK;"
fi
cmd="-e '$cmd'"
$mysql $mysqlArgs $cmd $dbName # this does not work
# if I copy the following output to console, it works fine
echo "$mysql $mysqlArgs $cmd $dbName"
done
“回声”显示如下:
/usr/bin/mysql -u root -e 'START TRANSACTION; ALTER TABLE `test` DROP COLUMN `contactTypeId`;; ROLLBACK;' testdb