当没有添加目录或文件时,grep会做什么

Top*_*der 3 bash grep

我最近一直在使用egrep命令(只是出于对grep的偏好)而且我注意到了一个我不完全理解的行为.当我在我的主目录中运行以下命令时: egrep -r "main" * 它执行我期望的操作并返回包含"main"的所有行和相应文件.

虽然如果我进入: egrep -r "main" 并且忘记将明星放在最后,它似乎只是永远挂起.我希望有人能够阐明为什么会这样做以及它在做什么?

谢谢 :)

Ane*_*new 6

它正在等待输入,stdin因为您没有从grep联机帮助页指定文件名:

NAME
   grep, egrep, fgrep - print lines matching a pattern

SYNOPSIS
   grep [options] PATTERN [FILE...]
   grep [options] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
   Grep searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN.  By default, grep
   prints the matching lines.
Run Code Online (Sandbox Code Playgroud)