On Tue, Sep 10, 2019 at 05:58:53PM +0100, Raf Czlonka wrote:
> On Tue, Sep 10, 2019 at 05:53:34PM BST, Todd C. Miller wrote:
> > On Tue, 10 Sep 2019 16:56:42 +0100, Raf Czlonka wrote:
> > 
> > > How about ditching dirname(1)?
> > 
> > dirname(1) handles files in the root directory as well as files
> > with no directory correctly, your diff does not.
> > 
> > E.g.
> > 
> > FCODES=/foo
> > ${FCODES%/*} -> ""
> > dirname $FCODES -> "/"
> > 
> > FCODES=bar
> > ${FCODES%/*} -> ""
> > dirname $FCODES -> "."
> > 
> > I think it best to keep dirname rather than try to reimplement it
> > in the shell.
> > 
> >  - todd
> 
> Fair enough.
> 
> FYI, what prompted me to use shell instead of dirname(1) is the
> recent removal of basename(1)[0] but it seems like the latter doesn't
> suffer from similar edge cases :^)

The only potential issue with basename versus chopping things off until
the last slash with a parameter substitution is if you're dealing with
paths to directories and you're not sure whether there may be a slash
at the end or not. If there is, basename will give you "/a/b/" --> "b"
while the substitution would give you an empty string.


> 
> [0] 
> http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/etc/rc.d/rc.subr.diff?r1=1.131&r2=1.132&sortby=date&f=h
> 
> Thanks for pointing that out!
> 
> Raf

Reply via email to