Subject: Re: bug#8420: dirname

From: Etienne Buira <[email-masked]>
Date: Mon, 4 Apr 2011 18:13:24 +0200

On Mon, Apr 04, 2011 at 03:43:36PM +0200, Michele Marigliano wrote:
> Hi, 

Hi.

> I execute the following bash command on RH 5.3 
> 
> CURRENT_DIR=`/usr/bin/dirname $0`

Beware that it will give the script dirname (if specified), not the
current working directory (that you can get using pwd).

> /usr/bin/dirname: invalid option -- b
> 
> Try `/usr/bin/dirname --help' for more information.
> 
> [oracle@mpawls ~]$ /usr/bin/dirname --version
> 
> dirname (GNU coreutils) 5.97

You might want to upgrade, it is an ancient version.

> $ echo $0
> -bash

Options are introduced by a hyphen (which your binary name starts with),
if you want to tell that what follows is not option anymore, you want
to use '--'. So your lines looks like that:
CURRENT_DIR=`/usr/bin/dirname -- $0`
(works at least with coreutils8.7, don't know about your version).

> $ echo $0
> 
> -bash
> 
> $ dirname
> 
> dirname: too few arguments

Yes, it understood it like "dirname -b -a -s -h", whithout any filepath.