Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Linux 为什么可以';t将文件路径参数传递给shell命令';更多';管道模式?_Linux_Shell_Pipe_Pipeline - Fatal编程技术网

Linux 为什么可以';t将文件路径参数传递给shell命令';更多';管道模式?

Linux 为什么可以';t将文件路径参数传递给shell命令';更多';管道模式?,linux,shell,pipe,pipeline,Linux,Shell,Pipe,Pipeline,我有一个文本文件a.txt hello world 我使用以下命令: cmd1: cmd2: 我认为cmd2应该等于echo'a.txt'| xargs-I more{},但事实并非如此 我想知道为什么cmd2会这样工作,以及如何编写在管道模式下工作方式不同的代码。使用重定向或如果echo'a.txt';更多的按照您期望的方式工作,那么journalctl |更多的无法工作,因为它期望journalctl的输出是一个文件名列表,而不是要显示的实际内容。也就是说,一个通用的“UNIX语义是如何工

我有一个文本文件a.txt

hello world
我使用以下命令:

cmd1:

cmd2:


我认为cmd2应该等于
echo'a.txt'| xargs-I more{}
,但事实并非如此


我想知道为什么cmd2会这样工作,以及如何编写在管道模式下工作方式不同的代码。

使用
重定向或
如果
echo'a.txt';更多的
按照您期望的方式工作,那么
journalctl |更多的
无法工作,因为它期望
journalctl
的输出是一个文件名列表,而不是要显示的实际内容。也就是说,一个通用的“UNIX语义是如何工作的?”问题更适合于or,而不是堆栈溢出。让我们来翻表
echo foo | more
输出
foo
,那么为什么
more foo
输出名为
foo
的文件的内容呢?这两个问题的答案是:标准输入和参数是两个完全不同的接口,处理不同的用例。你为什么这么想?如果它们是等价的,那么为什么会有人使用
xargs
$ more a.txt
output:

hello world
$ echo 'a.txt'|more
output:

a.txt
printf '%s\0' a.txt b.txt |
  xargs -0 cat -- |
  more