Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 我如何告诉LinuxBash忽略回跳?_Mysql_Linux_Bash_Chef Infra - Fatal编程技术网

Mysql 我如何告诉LinuxBash忽略回跳?

Mysql 我如何告诉LinuxBash忽略回跳?,mysql,linux,bash,chef-infra,Mysql,Linux,Bash,Chef Infra,我正在编写一个厨师食谱,它调用mysql命令并执行查询。问题是,传递到此命令的查询可能有反勾号,而我对此没有控制权。我会这样做: mysql --user=#{user} #{db_name} --execute="CALL someStoredProcedure(\"A String\", \"A QUERY\");" 执行“更新客户段自定义条件”{无空间段名称} 操作:运行 命令“mysql--user={user}{db_name}--execute=”callsomestoredpr

我正在编写一个厨师食谱,它调用
mysql
命令并执行查询。问题是,传递到此命令的查询可能有反勾号,而我对此没有控制权。我会这样做:

mysql --user=#{user} #{db_name} --execute="CALL someStoredProcedure(\"A String\", \"A QUERY\");"

执行“更新客户段自定义条件”{无空间段名称}
操作:运行
命令“mysql--user={user}{db_name}--execute=”callsomestoredprocesse(\“A String\”,\“一个包含反勾号的查询,我没有需要逐字传递的控制权\)”;"
结束

但是Bash总是抱怨语法,因为它试图解释反勾号和求值。我怎么能告诉它完全忽略这个字符呢


仅供参考,这是在chef
execute
块中作为
命令调用的,因此使用#for变量。

您也可以在chef中使用
execute
资源,而不是
bash
。这不会使用bash,因此反勾号没有特殊意义

编辑:

更具体地说,您发布的示例资源

execute "update_customer_segment_custom_condition_#{no_space_segment_name}" do
  command ['mysql', "--user=#{user}", db_name, '--execute="CALL someStoredProcedure(\"A String\", \"A QUERY CONTAINING BACKTICKS OVER WHICH I HAVE NO CONTROL THAT NEEDS TO BE PASSED VERBATIM\");"']
end 

命令的数组形式
关闭shell的任何处理。

这可能是因为您使用ruby(我不知道ruby)构建了一个字符串,然后将其传递到一个shell中,并使用action run执行

这已经有一个问题,因为双引号以中间字符串结尾:

命令“mysql--user={user}{db\u name}--execute=“调用someStoredProcedure(\'A String\”,\'A QUERY,其中包含需要逐字传递的我无法控制的倒勾号;”

因此,我想知道ruby是否没有在这里为结尾的补充“提供语法错误

要生成的字符串(可能)如下所示:

mysql --user=#{user} #{db_name} --execute="CALL someStoredProcedure(\"A String\", \"A QUERY\");"
您需要这样生成它:

mysql --user=#{user} #{db_name} --execute='CALL someStoredProcedure("A String", "A QUERY");"

和“一个查询”部分“您需要将所有出现的
'
替换为
'\'
,否则您仍然可以获得shell代码注入。”

bash
中,变量的前缀是
$
,而不是
#
。这是Ruby代码,因为该命令是通过Chef组装的。如果处理原始bash,我计划在
--execute='…command…'
参数周围使用单引号(这样就不需要转义嵌入的双引号)(当然,也可以使用反引号),但您确实需要担心MySQL是否会使用单引号)。我不确定你是否可以在通往MySQL的管道中的某个地方更改它。是的,在反复使用它之后,确保正在执行的命令周围有单引号似乎是可行的。无论如何,我都会让我的同事检查它。然后,不会调用bash,它只是通过mixlib shellout。我想我可以指定解释器并尝试其中一个。不,这已经是您想要的了。在运行这样的命令时不需要bash。您是否确实看到它尝试评估backticks?如果我在mac上使用irb并创建mixlib::shellout.new('echo
which ls
'))我得到了/bin/ls。换句话说,它解释了我的backtics并执行它们。如果我回显$SHELL,我得到了/bin/bash。因此,看起来,至少在osx上,mixlib SHELL out可以使用bash。不确定这会不会发生。mixlib::shellout.new(['echo','which ls`')。点击{a{a}a.run u命令}.stdout==“`哪个ls`\n”