[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grep --directories option

From: Paul Eggert
Subject: Re: Grep --directories option
Date: Fri, 30 May 2003 17:32:06 -0700

> From: (Paul Jarc)
> Date: Fri, 30 May 2003 17:39:14 -0400

> I suggest making the default "skip with a warning":
> $ mkdir foo
> $ grep pattern foo; echo $?
> grep: foo: skipping directory

OK, how about this solution instead?

* Have --directory='read' be the default, but if grep determines that a
  read fails because it is reading a directory, it outputs a diagnostic
  like this:

  grep: foo: skipping unreadable directory

  grep can then go on to the next file, but it must exit with status 2 if
  this diagnostic is generated.

This behavior would conform to POSIX.  As I read it, POSIX requires
that "grep foo dir" must work if one can read dir as if it were a
file, and if the resulting bytes are the bytes of a text file.  It
also requires that 'grep' must output a diagnostic and must fail
(i.e. exit with status 2) if the 'read' fails.

> Date: Fri, 30 May 2003 14:11:11 -0700
> From: Jeff Bailey <>

> I don't have my copy of Posix handy - Is there a rule saying that
> directories cannot be textfiles?

Sorry: I thought there was a rule, but on more careful reading I was
mistaken.  So please withdraw my suggestion of making --recursive the

> Date: Fri, 30 May 2003 17:21:04 -0400 (EDT)
> From: (James Morrison)
>    Having the default be --directories='skip' is less useful, and would
>    confuse new users more.  Normally if a user wants to grep a directory,
>    they are probably thinking of the files under the directory, not the
>    directory itself.
>  I think skip would be the least surprising.

As I read the spec, POSIX does not allow 'skip' to be the default.  To
conform to POSIX, we must either make 'read' the default, or we must
come up with another behavior that conforms to POSIX and make that the
default.  The simplest is to make 'read' the default.

> for the Hurd I think the common case should be skip and add an
> option, -R, which is the same as -d read for GNU Hurd based systems.

But that would be an incompatible change, as -R already means the same
as --recursive.

I still oppose the idea of having "the default depend on the OS".
grep's behavior should be portable.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]