如何将一个NULL字节作为参数转义为Makefile中的shell命令 [英] How to escape a NULL byte as an argument to a shell command inside a Makefile
本文介绍了如何将一个NULL字节作为参数转义为Makefile中的shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Makefile里面我运行一个shell命令,我想传递一个NULL字节作为参数。以下尝试失败:
echo $(shell / bin / echo -n $$'\x00'| ruby -e put STDIN.read.inspect)
它生成:
echo$ \\x00
相反,我预计:
echo\\\
pre>
如何正确地转义这样一个NULL字节?
解决方案由于execve(2)语义,不可能传递一个包含空字节作为参数的字符串。每个参数字符串由空字节终止,因此无法区分包含的空字节和字符串的结尾。
Inside a Makefile I run a shell command which I want to pass a NULL byte as argument. The following attempt fails:
echo $(shell /bin/echo -n $$'\x00' | ruby -e "puts STDIN.read.inspect")
It generates:
echo "$\\x00"
Instead I expected:
echo "\u0000"
How do I properly escape such a NULL byte?
解决方案Due to the execve(2) semantics it is not possible to pass a string containing a null byte as argument. Each argument string is terminated by null byte, therefore making it impossible to distinguish between the contained null byte and the end of the string.
这篇关于如何将一个NULL字节作为参数转义为Makefile中的shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文