bug-coreutils
[Top][All Lists]
Advanced

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

bug#6124: basename/dirname are not POSIX compliant on arg starting with


From: Vincent Lefevre
Subject: bug#6124: basename/dirname are not POSIX compliant on arg starting with a dash
Date: Thu, 6 May 2010 15:23:38 +0200
User-agent: Mutt/1.5.20-6083-vl-r35499 (2010-04-24)

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 <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)







reply via email to

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