
從手冊來看grep
,grep 用法的一般形式是:
grep options pattern input_file_names
特別是,它指出「可以有零個或多個輸入檔名」。
如果文件名為零,哪些文件是搜尋的候選文件?前任。grep mystr
答案1
從man grep
:
file A pathname of a file to be searched for the patterns. If no file
operands are specified, the standard input shall be used.
因此,如果不涉及管道或重定向,它將等待您輸入一些文字。
答案2
它從其讀取標準輸入(檔案描述符 0)如果沒有給出任何檔案名稱。
grep foo
相當於:
grep foo -
這允許這樣的事情:
grep foo < file
或者:
cmd | grep foo
如果grep foo
在終端機中的互動式 shell 提示字元下執行,則將grep
從終端設備讀取,即從您透過鍵盤輸入的內容讀取。