我怀疑more
命令。通常,more
无法从stdin
读取,但使用管道从stdin读取内容。
例如,在尝试执行more
命令以从stdin
获取输入时,它正在拒绝。
$ more [Enter]
Usage: more [options] file...
Options:
-d display help instead of ring bell
-f count logical, rather than screen lines
-l suppress pause after form feed
-p suppress scroll, clean screen and disblay text
-c suppress scroll, display text and clean line ends
-u suppress underlining
-s squeeze multiple blank lines into one
-NUM specify the number of lines per screenful
+NUM display file beginning from line number NUM
+/STRING display file beginning from search string match
-V output version information and exit
但是,这里是从管道stdin
获取输入。
$ cat file.txt
This is for testing purpose
$ cat file.txt | more
This is for testing purpose
我想知道这是怎么回事(意思是不是从stdin
阅读而是从管道stdin
阅读?
答案 0 :(得分:4)
more
区分其标准输入是来自TTY还是来自其他地方(管道,常规文件等)。如注释中所述,如果输入来自TTY,more
拒绝运行,因为它需要TTY来读取其命令键击。另一方面,cat
不是交互式的,并且没有明确地处理TTY,所以它可以不关心它的输入是TTY还是其他类型的打开文件。
根据标准输入或输出是否为TTY,还有许多其他Unix实用程序的行为方式不同。例如,ls
将其输出格式化为多列,而ls | cat
则不会。