写一个脚本zl.sh,用来删除数据库mydatabase中某个表mytable的某行数据:
#!/bin/bash
HOSTNAME="127.0.0.1"
PORT="2918"
USERNAME="root"
PASSWORD="root"
TABLENAME="mydatabase"
DATABASEUSERDB="mytable"
MYSQL_CMD="mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD}"
alter_table_sql = "delete from ${TABLENAME} where id = '123'"
echo ${alter_table_sql} | ${MYSQL_CMD} ${DATABASEUSERDB}
执行脚本:sh zl.sh
报错:alter_table_sql:not found
解决方法:
alter_table_sql和等号之间不要有空格:
alter_table_sql="delete from ${TABLENAME} where id = '123'"