在模拟文件的命令行上进行管道传输?
我以前见过这种技术,但不知道它叫什么,也忘记了确切的语法。假设我需要将一个文件通过管道输入到一个程序中,例如:command <输入文件。但是,我想直接将输入文件的这些行传递到命令中,而不需要中间输入文件。它看起来像这样,但它不起作用:
command < $(file-line1; file-line2; file-line3)
有人能告诉我这叫什么以及如何做吗?
I've seen the technique before, but don't know what it's called and forget the exact syntax. Let's say I need to pipe in a file to a program like: command < input-file. However, I want to directly pass these lines of the input file into the command without the intermediate input file. It looks something like this, but it doesn't work:
command < $(file-line1; file-line2; file-line3)
Can someone tell me what this is called and how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这称为
进程替换
有了上面的内容,
command
就会认为它正在输入一个名称很像/dev/fd/XX
的文件,其中“XX”是一些数字。正如您所提到的,这是一个临时文件(实际上是一个文件描述符),但它将包含您传递给 printf 命令的 3 行。This is called
Process Substitution
With the above,
command
will think its being input a file with a name much like/dev/fd/XX
where 'XX' is some number. As you mentioned, this is a temporary file (actually a file descriptor) but it will contain the 3 lines you passed in to theprintf
command.这里的字符串。
或者heredoc。
Herestring.
Or heredoc.
我认为您指的是“此处文档”。像这样
I think you are referring to a "here document". Like this
怎么样:
How about: