我将bash文件进程的结果转化为一个变量。变量内容应该从bash插入到mysql表中:
content="File '/test.csv' was imported"
mysql --user=root --password=rootpw --database=$DB
-e "INSERT INTO mytable VALUES(1, '$content')"结果:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax
to use near '' was imported' at line 1问题:当插入mysql时,我如何处理变量中包含的单引号?
我尝试了$content、'$content'和"$content"的所有变体,但它们都不起作用。
发布于 2022-08-04 06:39:18
内部报价需要加倍。试一试
mysql --user=root --password=rootpw --database=$DB
-e "INSERT INTO mytable VALUES(1, '${content//\'/\'\'}')"https://stackoverflow.com/questions/73231028
复制相似问题