[Top][All Lists]

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

dirname - bug or feature?

From: Fill Manuel
Subject: dirname - bug or feature?
Date: Fri, 23 Feb 2007 10:16:55 +0100


I recently realised that the dirname-program from the coreutils-5.2.1-23.8 - 
package doesn't take ".." and "." as Parent-Directory or Current-Directory and 
because of that I decided to write a similar program in Perl that does the same 
task as dirname but with some more features. To show you what I don't like 
about the original dirname I'll give you some examples:

address@hidden:~> dirname ../testfile
address@hidden:~> dirname-ng.pl ../testfile

As you can see my version of the program interprets the ".." as parent 
directory and "." as current directory and always returns the absolute path to 
the user. My version also doesn't allow going "over" root-directory. Like this 

address@hidden:~> dirname ../../../././testfile
address@hidden:~> dirname-ng.pl ../../../././testfile

There was also another thing I didn't like about this version: You can't work 
with file-lists. dirname always needs ONE path to work. I also "fixed" this  
issue. My version can work with many files. An example to show you what I mean:

address@hidden:~> dirname ../testfile /tmp/testfile2
dirname: too many arguments
Try `dirname --help' for more information.
address@hidden:~> dirname-ng.pl ../testfile /tmp/testfile2

and another example:

address@hidden:~> find /tmp/test/* | dirname | sort | uniq
dirname: too few arguments
Try `dirname --help' for more information.
address@hidden:~> find /tmp/test/* | dirname-ng.pl - | sort | uniq
address@hidden:~> find /tmp/test/*

As you can see here, my version can also handle input from STDIN with the "-" 

I don't think the issues I listed are "real" bugs, but lack of features. Maybe 
you think about implementing some of these features in futures releases. I 
append my version of the program. Feel free to modify and change the sourcecode 
if you like to. It's public domain.

Have a nice day :)

Mit freundlichen Grüßen / Best regards

Manuel Fill
IT Rechenzentrum UNIX-Basis

Fritz Egger GmbH & Co.
Weiberndorf 20
A-6380 St. Johann in Tirol

Tel:    +43 (0) 50600-10389
Fax:    +43 (0) 50600-90389
e-mail: mailto:address@hidden
Internet:       http://www.egger.com

Attachment: dirname-ng.pl
Description: dirname-ng.pl

reply via email to

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