GNU bug report logs -
#6124
basename/dirname are not POSIX compliant on arg starting with a dash
Previous Next
Reported by: Vincent Lefevre <vincent <at> vinc17.net>
Date: Thu, 6 May 2010 11:36:02 UTC
Severity: normal
Tags: notabug
Merged with 6123
Done: Jim Meyering <jim <at> meyering.net>
Bug is archived. No further changes may be made.
Full log
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
On 2010-05-06 13:50:27 +0100, Pádraig Brady wrote:
> The above busybox behavior implies that
> if you write a robust script like this for coreutils,
> that it is not portable to busybox:
>
> base=$(basename -- "$path")
If one follows POSIX, the correct way to do it is:
base=$(basename "$path")
and this is robust because the first argument is necessarily the path
(it cannot be an option, even "--").
> That also implies that we can't change the behavior.
According to
grep 'basename --' /usr/bin/*
grep 'basename \$' /usr/bin/*
on my Debian machine, almost all scripts use basename without "--".
The only exceptions are autoconf (but I'm not sure this counts, as
there's a test for "basename --" first, and I don't know what it
really expects) and savelog (from the debianutils package, thus
specific to Debian, but savelog also uses `basename $0`, so that
it is already inconsistent). Therefore I assume that changing
coreutils would be easier.
> Because there is an optional suffix parameter, one can't
> know which behavior is required for the above example.
> I suppose one could choose based on POSIXLY_CORRECT.
I think that it should really behave correctly if POSIXLY_CORRECT
is set, but also if it isn't set, given what appears to be the
current practice.
> Note solaris behaves like busybox and openbsd behaves like coreutils.
Perhaps they're copying coreutils without looking at what POSIX says.
--
Vincent Lefèvre <vincent <at> vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)
This bug report was last modified 14 years and 117 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.