Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
Shell Cat无法获取管道的内容?_Shell - Fatal编程技术网

Shell Cat无法获取管道的内容?

Shell Cat无法获取管道的内容?,shell,Shell,有一个名为test的文件,test上只有一行,haha tiger@debian:~$ cat test haha tiger@debian:~$ cat 'test' haha 为什么下面的命令不能获取haha?为什么ls test输出test,为什么ls test | cat不能输出haha tiger@debian:~$ ls test test ls test | cat test 我的系统是debian+bash问题不是管道本身,而是ls test没有输出文件test的内容ls

有一个名为test的文件,test上只有一行,
haha

tiger@debian:~$ cat test
haha
tiger@debian:~$ cat 'test'
haha
为什么下面的命令不能获取
haha
?为什么ls test输出
test
,为什么ls test | cat不能输出
haha

tiger@debian:~$ ls test
test
ls test  | cat 
test

我的系统是debian+bash

问题不是管道本身,而是
ls test
没有输出文件
test
的内容
ls
列出目录内容
ls测试
将只输出
测试


如果您确实希望使用管道显示
test
的内容,可以使用:

cat test | xargs echo

你可以看看“人猫”

使用时
cat test
cat'test'
,shell假定第二个参数始终是文件名


但是,使用管道,cat希望得到一组文本,因此,会打印“ls”的内容。

如果您确实希望这样显示文件的内容,请尝试

ls test | xargs cat

如果您确实希望使用管道来显示
测试的内容
,您应该重新考虑您正在做什么。如果您只想打印文件的内容,那么就没有理由使用管道。