因此,我需要从文件中读取一组ID号,并对每个ID号执行mysql查询。我开始的时候是这样的:
#!/bin/bash
file="eidlist.txt"
while IFS= read -r line
do
mysql --host <redacted> --user <redacted> --password=<redacted> -N -e "use netops;select m_mailname from footprints where m_empno=$line;"
done <"$file"这将工作并产生预期的输出。现在我需要做同样的事情,但是使用不同的ID列表,查询不同的字段。由于我现在查询的字段包含字母数字值(而前一个字段完全是数字的),我需要在mysql查询字符串中用引号将值括起来,我用\“like:
#!/bin/bash
file="pidlist0.txt"
while IFS= read -r line
do
mysql --host <redacted> --user <redacted> --password=<redacted> -N -e "use netops;select m_mailname from footprints where m_stuid=\"$line\";"
done <"$file"这不起作用--脚本不会产生任何输出。我做错了什么?
当我在命令行测试mysql命令(将$line变量预先填充到文件中的一个值中)时,它可以工作,但当从脚本内部运行时,它不会产生任何输出。到底怎么回事?
发布于 2016-11-08 04:28:12
只需使用m_stuid='$line';“?或将double改为single。
https://stackoverflow.com/questions/40473689
复制相似问题