On 2010-05-17 11:36, Eric Blake wrote:
On 05/17/2010 09:17 AM, Filipus Klutiero wrote:
Strip the last component and resulting trailing slashes; if the file
name contains only one component, print '.'.
But I welcome your ideas for a coherent sentence.
That sounds more correct and comprehensible. I don't know how many
corner cases there are and if they can all be covered in the help, but
there's also the no component case:
$ dirname ''
prints ".".
Yes, that's a corner case not covered by the above sentence, which we
could fix with "if the file name contains less than two components,
print '.'".
$ dirname /
prints "/".
I tend to classify the all-slash corner case as being one component, not
zero components. You can view it as the root directory being contained
in (well, reachable from) the root directory, as evidenced by '/../'
resolving to '/'.
Hum, interesting, never thought about "/../". I believe all-slash can't
be considered as being one component. According to POSIX, a component
needs at least one character.
But that doesn't work as well with the '<2
components' wording above, so I'm feeling more comfortable with leaving
the corner-cases undocumented in the terse --help output, by using your
view that '/' has no components rather than 1, and anyone worried about
the two corner cases of '' and '/' can read the info page.
Using If-s is a good idea. I would agree with leaving the no components
case to the documentation proper. Here is a simple even though
incomplete description based on yours. It is exact *AFAIK*. I'm using
"pathname" instead of "file name", since file name doesn't fit the Base
Specifications definition - but I don't know if coreutils/GNU is
willingly using its own terminology.
If the pathname contains several components, strip the last component
and resulting trailing slashes; if the pathname contains only one
component, print '/' if the pathname starts with a slash, '.' otherwise.