GNU bug report logs - #9450
Bug report on 'dirname' : when jokers match several files

Previous Next

Package: coreutils;

Reported by: "Laurent TARRISSE" <ltarrisse <at> midilibre.com>

Date: Tue, 6 Sep 2011 14:03:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9450 in the body.
You can then email your comments to 9450 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#9450; Package coreutils. (Tue, 06 Sep 2011 14:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Laurent TARRISSE" <ltarrisse <at> midilibre.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 06 Sep 2011 14:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Laurent TARRISSE" <ltarrisse <at> midilibre.com>
To: <bug-coreutils <at> gnu.org>
Subject: Bug report on 'dirname' : when jokers match several files
Date: Tue, 6 Sep 2011 15:53:10 +0200
[Message part 1 (text/plain, inline)]
Hi

Here this a strange behaviour using 'dirname' with joker filename:

>ll  /tmp/*.out
ls: /tmp/*.out: No such file or directory
>dirname /tmp/*.out
/tmp

That's OK. But if several files match the argument given :

>ll  /home/qualiac/mdl/scriptsJDM/QuaToCov/emission/*.HL
-rw-r--r--  1 qualiac qualiac 20715696 Sep  6 02:15 /home/qualiac/mdl/scriptsJDM/QuaToCov/emission/M399111H.HL
-rw-r--r--  1 qualiac qualiac  1181326 Sep  6 02:16 /home/qualiac/mdl/scriptsJDM/QuaToCov/emission/T399111H.HL
-rw-r--r--  1 qualiac qualiac   225012 Sep  6 02:15 /home/qualiac/mdl/scriptsJDM/QuaToCov/emission/T399211H.HL
>dirname  /home/qualiac/mdl/scriptsJDM/QuaToCov/emission/*.HL
dirname: too many arguments
Try `dirname --help' for more information.

That's bad. If I try:

>dirname '/home/qualiac/mdl/scriptsJDM/QuaToCov/emission/*.HL'
/home/qualiac/mdl/scriptsJDM/QuaToCov/emission

That's OK.

Could 'dirname' process only its first parameter ?

Thanks.


----------------------------------------------
UNIX VERSION:
----------------------------------------------
>uname -a
Linux jdm-qualiac-srv-trv.midilibre.com 2.6.9-100.ELsmp #1 SMP Tue Feb 1 12:04:42 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
>uname -r
2.6.9-100.ELsmp
>cat /etc/issue
Red Hat Enterprise Linux ES release 4 (Nahant Update 9)
Kernel \r on an \m
[Message part 2 (text/html, inline)]

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#9450; Package coreutils. (Tue, 06 Sep 2011 14:29:01 GMT) Full text and rfc822 format available.

Message #8 received at 9450 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Laurent TARRISSE <ltarrisse <at> midilibre.com>
Cc: 9450 <at> debbugs.gnu.org
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several
	files
Date: Tue, 06 Sep 2011 08:24:17 -0600
9450 tag wishlist
thanks

On 09/06/2011 07:53 AM, Laurent TARRISSE wrote:
> Hi
>
> Here this a strange behaviour using 'dirname' with joker filename:

The term is 'wildcard', not 'joker'

> dirname: too many arguments
> Try `dirname --help' for more information.

Thanks for the report.  To some degree, this is expected behavior: POSIX 
requires that portable shell scripts pass exactly one argument to 
dirname, so passing 0 or more than 1 arguments is necessarily in the 
realm of non-portable code, and we would rather error out if we don't 
have any better defined semantics for an extension.

> Could 'dirname' process only its first parameter ?

No.  But there _has_ been requests in the past to add an extension to 
GNU coreutils to match BSD dirname/basename semantics of optionally 
taking more than one parameter:

https://lists.gnu.org/archive/html/bug-coreutils/2010-05/msg00015.html

But so far, no one has submitted patches.  Therefore, I'll keep this bug 
report open, but tag it as a wishlist.

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#9450; Package coreutils. (Tue, 06 Sep 2011 15:34:02 GMT) Full text and rfc822 format available.

Message #11 received at 9450 <at> debbugs.gnu.org (full text, mbox):

From: "Laurent TARRISSE" <ltarrisse <at> midilibre.com>
To: "Eric Blake" <eblake <at> redhat.com>
Cc: 9450 <at> debbugs.gnu.org
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several
	files
Date: Tue, 6 Sep 2011 16:37:29 +0200
----- Original Message ----- 
From: "Eric Blake" <eblake <at> redhat.com>
To: "Laurent TARRISSE" <ltarrisse <at> midilibre.com>
Cc: <9450 <at> debbugs.gnu.org>
Sent: Tuesday, September 06, 2011 4:24 PM
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several 
files


> 9450 tag wishlist
> thanks
>
> On 09/06/2011 07:53 AM, Laurent TARRISSE wrote:
>> Hi
>>
>> Here this a strange behaviour using 'dirname' with joker filename:
>
> The term is 'wildcard', not 'joker'

Please accept my apologizes. I'm french :)

>
>> dirname: too many arguments
>> Try `dirname --help' for more information.
>
> Thanks for the report.  To some degree, this is expected behavior: POSIX 
> requires that portable shell scripts pass exactly one argument to dirname, 
> so passing 0 or more than 1 arguments is necessarily in the realm of 
> non-portable code, and we would rather error out if we don't have any 
> better defined semantics for an extension.
>

OK for the answer.

>> Could 'dirname' process only its first parameter ?
>
> No.  But there _has_ been requests in the past to add an extension to GNU 
> coreutils to match BSD dirname/basename semantics of optionally taking 
> more than one parameter:
>
> https://lists.gnu.org/archive/html/bug-coreutils/2010-05/msg00015.html
>
> But so far, no one has submitted patches.  Therefore, I'll keep this bug 
> report open, but tag it as a wishlist.
>

Just let me explain... we had to reuse unix scripts, primarily written for 
HP UX

   >uname -a
   HP-UX ppbmo B.11.23 U ia64 3204054692 unlimited-user license

Some of our scripts, who did function perfectly on HP-UX for several years, 
encountered problems once moved on Linux platform.
One reason is due to dirname : on HP UX I can give several arguments to 
dirname, and as you say, on Linux I cannot. That's all. ;)




> -- 
> Eric Blake   eblake <at> redhat.com    +1-801-349-2682
> Libvirt virtualization library http://libvirt.org 





Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#9450; Package coreutils. (Tue, 06 Sep 2011 17:40:03 GMT) Full text and rfc822 format available.

Message #14 received at 9450 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Laurent TARRISSE <ltarrisse <at> midilibre.com>
Cc: 9450 <at> debbugs.gnu.org
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several
	files
Date: Tue, 6 Sep 2011 11:36:05 -0600
Laurent TARRISSE wrote:
> Just let me explain... we had to reuse unix scripts, primarily
> written for HP UX
> 
>    >uname -a
>    HP-UX ppbmo B.11.23 U ia64 3204054692 unlimited-user license
> 
> Some of our scripts, who did function perfectly on HP-UX for several
> years, encountered problems once moved on Linux platform.
> One reason is due to dirname : on HP UX I can give several arguments
> to dirname, and as you say, on Linux I cannot. That's all. ;)

On HP-UX if you give several option arguments to dirname then the
HP-UX dirname would handle the first argument and then return an
error due to the extra arguments.  See this example:

  $ /usr/bin/dirname /one/two/three /four/five /six/seven
  /one/two

  $ echo $?
  1

  $ /usr/bin/dirname /one/two/three
  /one/two

  $ echo $?
  0

It is an error on HP-UX dirname to supply extra arguments too.  But
your scripts must be ignoring the error.  GNU dirname is simply
reporting the error more loudly.  :-)

What is your script expecting to happen with the extra arguments?
Surely that would also be a bug in your script since those extra
arguments are not getting processed.

Bob




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#9450; Package coreutils. (Wed, 07 Sep 2011 07:27:01 GMT) Full text and rfc822 format available.

Message #17 received at 9450 <at> debbugs.gnu.org (full text, mbox):

From: "Laurent TARRISSE" <ltarrisse <at> midilibre.com>
To: "Bob Proulx" <bob <at> proulx.com>
Cc: 9450 <at> debbugs.gnu.org
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several
	files
Date: Wed, 7 Sep 2011 09:21:45 +0200
----- Original Message ----- 
From: "Bob Proulx" <bob <at> proulx.com>


> Laurent TARRISSE wrote:
>> Just let me explain... we had to reuse unix scripts, primarily
>> written for HP UX
>>
>>    >uname -a
>>    HP-UX ppbmo B.11.23 U ia64 3204054692 unlimited-user license
>>
>> Some of our scripts, who did function perfectly on HP-UX for several
>> years, encountered problems once moved on Linux platform.
>> One reason is due to dirname : on HP UX I can give several arguments
>> to dirname, and as you say, on Linux I cannot. That's all. ;)
>
> On HP-UX if you give several option arguments to dirname then the
> HP-UX dirname would handle the first argument and then return an
> error due to the extra arguments.  See this example:
>
>  $ /usr/bin/dirname /one/two/three /four/five /six/seven
>  /one/two
>
>  $ echo $?
>  1
>
>  $ /usr/bin/dirname /one/two/three
>  /one/two
>
>  $ echo $?
>  0
>
> It is an error on HP-UX dirname to supply extra arguments too.  But
> your scripts must be ignoring the error.  GNU dirname is simply
> reporting the error more loudly.  :-)

Yes, my script doesn't care about the return code.
I use the dirname to extract the path from a given file, and then
do a 'cd' command to that path :
   MY_PATH=`dirname $1`
   cd $MY_PATH
As you say, HP-UX dirname returns 1, but neveetheless outputs the path
of the first argument, and it's just what I expected him to do ! :))

> What is your script expecting to happen with the extra arguments?
> Surely that would also be a bug in your script since those extra
> arguments are not getting processed.

No because my script is less or more something equal to the FTP 'put' or
'mput' commands : you give it a file name as an argument, this file name can
contain a wildcard, so it can actually match several files of the 
filesystem.
The 'bug' appeared on Linux, because dirname doesn't output the path when
several arguments are passed to it. :))


> Bob 





Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Wed, 07 Sep 2011 14:38:01 GMT) Full text and rfc822 format available.

Notification sent to "Laurent TARRISSE" <ltarrisse <at> midilibre.com>:
bug acknowledged by developer. (Wed, 07 Sep 2011 14:38:02 GMT) Full text and rfc822 format available.

Message #22 received at 9450-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Laurent TARRISSE <ltarrisse <at> midilibre.com>
Cc: 9450-done <at> debbugs.gnu.org
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several
	files
Date: Wed, 07 Sep 2011 07:33:30 -0700
On 09/07/11 00:21, Laurent TARRISSE wrote:
> The 'bug' appeared on Linux, because dirname doesn't output the path when
> several arguments are passed to it. :)

The same 'bug' will also appear on Solaris 10; its
dirname does the same thing as GNU/Linux's dirname.

I'm afraid you're fighting an uphill battle here.
I'd fix the script rather than expecting
other implementations to match HP-UX's quirks.

I'm marking this as "done" since I don't expect
the GNU/Linux version to change.




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#9450; Package coreutils. (Wed, 07 Sep 2011 14:53:02 GMT) Full text and rfc822 format available.

Message #25 received at submit <at> debbugs.gnu.org (full text, mbox):

From: wyrm <at> haell.com
To: bug-coreutils <at> gnu.org
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several
	files
Date: Wed, 7 Sep 2011 07:10:23 -0700
On 2011-09-07 at 09:21:45 +0200, ltarrisse <at> midilibre.com wrote:
> Yes, my script doesn't care about the return code. I use the dirname
> to extract the path from a given file, and then do a 'cd' command to
> that path :
>     MY_PATH=`dirname $1`
>     cd $MY_PATH
> As you say, HP-UX dirname returns 1, but neveetheless outputs the path
> of the first argument, and it's just what I expected him to do ! :))

Place some quotes around the argument, so that the variable will expand
but the glob won't. Something like:
	MY_PATH=`dirname "$1"`
will probably do what you expect.

-- 
Confucius is inscrutable.
God is ineffable.
Beer is inevitable.




Message #26 received at 9450-done <at> debbugs.gnu.org (full text, mbox):

From: "Laurent TARRISSE" <ltarrisse <at> midilibre.com>
To: "Paul Eggert" <eggert <at> cs.ucla.edu>
Cc: 9450-done <at> debbugs.gnu.org
Subject: Re: bug#9450: Bug report on 'dirname' : when jokers match several
	files
Date: Wed, 7 Sep 2011 16:48:52 +0200
----- Original Message ----- 
From: "Paul Eggert" <eggert <at> cs.ucla.edu>


> On 09/07/11 00:21, Laurent TARRISSE wrote:
>> The 'bug' appeared on Linux, because dirname doesn't output the path when
>> several arguments are passed to it. :)
>
> The same 'bug' will also appear on Solaris 10; its
> dirname does the same thing as GNU/Linux's dirname.
>
> I'm afraid you're fighting an uphill battle here.
> I'd fix the script rather than expecting
> other implementations to match HP-UX's quirks.
>
> I'm marking this as "done" since I don't expect
> the GNU/Linux version to change.

You are right. In fact, I do not expect any more that the
Linux version change, and I already fixed my script to
deal with this feature.
However, the advice given by an anonymous person
in the preceding email:

>Place some quotes around the argument, so that the variable will expand
>but the glob won't. Something like:
>MY_PATH=`dirname "$1"`
>will probably do what you expect.

worked perfectly    oo
Thanks to him (I cannot respond to him thus the 'sender email' is 
unreachable)
because 





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 06 Oct 2011 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 339 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.