Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.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
将以null结尾的字符串传递给bash函数_Bash - Fatal编程技术网

将以null结尾的字符串传递给bash函数

将以null结尾的字符串传递给bash函数,bash,Bash,我的导出功能: myfunc(){ # Some operation with null terminated string # If I use $1, is it guaranteed that it is a null terminated string? } 在本例中,请考虑 find . -type -f -print0 | while read -rd '' line do myfunc "$line" done 如果您使用的是print0,那么请确保除了在read中使用-d'之

我的导出功能:

myfunc(){
# Some operation with null terminated string
# If I use $1, is it guaranteed that it is a null terminated string?
}
在本例中,请考虑

find . -type -f -print0 | while read -rd '' line
do
myfunc "$line"
done

如果您使用的是
print0
,那么请确保除了在
read
中使用
-d'
之外,还使用空的
IFS=
,以将空值作为分隔符:

while IFS= read -r -d '' line; do
   myfunc "$line"
done < <(find . -type f -print0)
而IFS=read-r-d''行;做
myfunc“$line”

完成<如果您使用
“$1”
,那么我认为是这样的。Bash字符串总是以NUL结尾,这意味着它们不能包含NUL字符。也许你不是这个意思,谢谢。。为什么
IFS=
除了
d'
?@mona_-sax,因为除非
IFS
被清除,否则后面的空白可以被
read
@anubhava剪除,….虽然只有一个参数传递给
read
并且没有
-a
,但实际上并没有进行拆分。。。