GNU bug report logs - #22128
dirname: accept file list input

Previous Next

Package: coreutils;

Reported by: "Nellis, Kenneth" <Kenneth.Nellis <at> xerox.com>

Date: Thu, 10 Dec 2015 01:09:02 UTC

Severity: wishlist

Tags: wontfix

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


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

From: Pádraig Brady <P <at> draigBrady.com>
To: Stephane Chazelas <stephane.chazelas <at> gmail.com>, 22128 <at> debbugs.gnu.org
Subject: Re: bug#22128: dirname enhancement
Date: Fri, 11 Dec 2015 18:38:15 +0000
On 11/12/15 14:46, Stephane Chazelas wrote:
> 2015-12-10 10:40:30 -0700, Bob Proulx:
> [...]
>> In this instance the first thing I thought of when I read your dirname
>> -f request was a loop.
>>
>>    while read dir; do dirname $dir; done < list
> 
> "read dir" expects the input in a very specific format and
> depends on the current value of IFS (like a dir called "my\dir "
> has to be input as "my\\dir\ " with the default value of IFS)
> and can't accept dir names with newline characters.
> 
> Invoking the split+glob operator on $dir doesn't make sense here
> unless you mean the input to be treated as a $IFS delimited list
> of patterns.
> 
> If the intention was to treat the input as a list of file
> paths, one per line (so can't do file paths with newline
> characters), then that would rather be:
> 
>  while IFS= read -r dir; do dirname -- "$dir"; done < list
> 
>>
>> Pádraig suggested xargs which was even shorter.
>>
>>   xargs dirname < filename
> 
> That expects yet another input format. That time, it can cope
> with any file path, since newline can be specified using quotes
> like:
> 
> "my dir
> with newline"
> 
> The output of dirname however won't be post-processable.

Both GNU basename and dirname since 8.16 (2012) got
the -z option to make the _output_ post-processable,
along with support for processing multiple inputs.

xargs splits arguments on the _input_ appropriately.
In general xargs is fine for this when the tool
doesn't need to process all inputs at once
(like sorting or generating a total for example).

cheers,
Pádraig.





This bug report was last modified 6 years and 215 days ago.

Previous Next


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