[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep . /; echo $?
From: |
Julian Foad |
Subject: |
Re: grep . /; echo $? |
Date: |
Mon, 24 Oct 2005 15:58:30 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050511 |
Dan Jacobson wrote:
In grep (GNU grep) 2.5.1, we see
-d ACTION, --directories=ACTION If an input file is a
directory, use ACTION to process it. By default, ACTION
is read, which means that directories are read just as
if they were ordinary files.
Indeed, the man page should mention that this is the case even with no -d!
It does: that's what "by default" means, since the argument to "-d" is not
optional. OK, the wording isn't as precise as it could be.
Or better yet, exit with a message and a different error value, and
document it.
At first sight this does seem to be a bug. Thank you for reporting it.
$ grep . /;echo $?
1
$ strace grep . /
...open("/", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFDIR|0755, st_size=1024, ...}) = 0
read(3, 0x8071000, 32768) = -1 EISDIR (Is a directory)...
For comparison, here is how it handles other problems with reading the files:
$ grep . @; echo $?
grep: @: No such file or directory
2
On the other hand, I wonder whether this behaviour was intentional. The "info"
help text says slightly more than the "man" page:
`--directories=ACTION'
If an input file is a directory, use ACTION to process it. By
default, ACTION is `read', which means that directories are read
just as if they were ordinary files (some operating systems and
filesystems disallow this, and will cause `grep' to print error
messages for every directory or silently skip them).
I don't know: it all seems a bit arbitrary and inconsistent. What's the point
of defaulting to ACTION="read" on systems that don't support it?
Perhaps we should just accept for the time being that Grep skips directories on
systems on which it cannot read them.
I'll at least make the man page text match the info text.
- Julian