Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.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
Bash xargs赢得';t在命令参数中使用回车文字_Bash_Xargs - Fatal编程技术网

Bash xargs赢得';t在命令参数中使用回车文字

Bash xargs赢得';t在命令参数中使用回车文字,bash,xargs,Bash,Xargs,考虑下面的grep命令,该命令用于匹配变量source\u files中列出的文件中的crlf行结尾 # In reality the variable "source_files" is constructed dynamically source_files="/foo/bar.txt" files_with_lf=$(echo "$source_files" | xargs -t -0 grep -Ua '\([^'$'\r'']\|^\)$') 这将打印: grep -Ua \([^]

考虑下面的grep命令,该命令用于匹配变量
source\u files
中列出的文件中的crlf行结尾

# In reality the variable "source_files" is constructed dynamically
source_files="/foo/bar.txt"
files_with_lf=$(echo "$source_files" | xargs -t -0 grep -Ua '\([^'$'\r'']\|^\)$')
这将打印:

grep -Ua \([^]\|^\)$ /foo/bar

grep: Unmatched [, [^, [:, [., or [=
似乎未正确传递
\r
文本。我怎样才能确保它是正确的呢

为了记录在案,我正在使用

$ bash --version
GNU bash, version 4.3.42(5)-release (x86_64-pc-msys)
Copyright (C) 2013 Free Software Foundation, Inc.

echo“$source\u files”
——您认为这有什么作用?别以为它会做你想做的事!我希望它能将
源文件的内容
放在标准输出上。你是在将文本字符串
/foo/bar.txt
变灰,而不是该文件的内容。也许你想要
cat
而不是
echo
。怎么会这样?中间有一个
xargs
调用…这正是grep需要的!grep[选项]。。。模式[文件]。。。