[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#6124: basename/dirname are not POSIX compliant on arg starting with
bug#6124: basename/dirname are not POSIX compliant on arg starting with a dash
Thu, 6 May 2010 15:23:38 +0200
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:
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.
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
> Note solaris behaves like busybox and openbsd behaves like coreutils.
Perhaps they're copying coreutils without looking at what POSIX says.
Vincent Lefèvre <address@hidden> - 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)
bug#6123: basename/dirname are not POSIX compliant on arg starting with a dash, Vincent Lefevre, 2010/05/06
bug#6124: basename/dirname are not POSIX compliant on arg starting with a dash, Eric Blake, 2010/05/06