有一个名为 test 的文件,test 上只有一行,haha
tiger@debian:~$ cat test
haha
tiger@debian:~$ cat 'test'
haha
为什么下面的命令不能得到haha? ls test输出test,为什么 ls test | 猫不能输出haha?
tiger@debian:~$ ls test
test
ls test | cat
test
我的系统是debian+bash
有一个名为 test 的文件,test 上只有一行,haha
tiger@debian:~$ cat test
haha
tiger@debian:~$ cat 'test'
haha
为什么下面的命令不能得到haha? ls test输出test,为什么 ls test | 猫不能输出haha?
tiger@debian:~$ ls test
test
ls test | cat
test
我的系统是debian+bash
问题不在于管道本身,而在于ls test不输出文件的内容test。ls列出目录内容。ls test将简单地输出test.
如果您绝对希望使用管道显示test您可以使用的内容:
cat test | xargs echo
If you really want to display the content of the file like that, try
ls test | xargs cat
你可以看看“人猫”
使用
cat testorcat 'test'时,shell 假定第二个参数始终是文件名。
然而,通过管道,cat 期望得到一堆文本,因此打印了 'ls' 的内容。