我正在处理一个脚本,每天dynamic地执行一些查询。 这些查询来自数据库中的一个表。
以下是查询表的示例输出:
+---------------+-------------------------------+---------+ | query_name | query | userid | +---------------+-------------------------------+---------+ | All_User | select * from users LIMIT 10; | jmatthe | +---------------+-------------------------------+---------+
现在,我必须执行查询select * from users LIMIT 10;
dynamic。 我正在读取输出的每一行,并从输出存储查询。
query_name=$(echo $query | cut -d\| -f1) query_sql=$(echo $query | cut -d\| -f2) query_user=$(echo $query | cut -d\| -f3)
现在问题出现在这里。 因为我的行包含一个*
字符,所以echo $query
将扩展*
以将其replace为当前目录中的文件。 所以基本上,我的query_sql
存储这样的东西。
select batchemail.sh query_output.txt from tbl_query
我想保留行中的*
,以便在我的query_sql
variables中得到相同的query_sql
。 我想我的query_sql
variables来存储原始数据。
select * from tbl_query
有人可以指导我吗?
您可以通过在脚本中添加以下行来禁用它:
set -o noglob
举个例子,
echo * your files and folders are shown here.. set -o noglob echo * *
你可以把它放进“”:
$ ls file1 file2 file3 file4 file5 file6 file7 file8 file9 $ Q='select * from table;' $ echo $Q select file1 file2 file3 file4 file5 file6 file7 file8 file9 from table; $ echo "$Q" select * from table;