[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 |
Hi,
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
/home
address@hidden:~>
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
example:
address@hidden:~> dirname ../../../././testfile
../../.././.
address@hidden:~> dirname-ng.pl ../../../././testfile
/
address@hidden:~>
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
/home
/tmp
address@hidden:~>
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
/tmp/test
/tmp/test/a
/tmp/test/b
/tmp/test/c
/tmp/test/d
address@hidden:~> find /tmp/test/*
/tmp/test/a
/tmp/test/a/testfile
/tmp/test/b
/tmp/test/b/testfile
/tmp/test/c
/tmp/test/c/testfile
/tmp/test/d
/tmp/test/d/testfile
address@hidden:~>
As you can see here, my version can also handle input from STDIN with the "-"
parameter.
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.
<<dirname-ng.pl>>
Have a nice day :)
Mit freundlichen Grüßen / Best regards
Manuel Fill
IT Rechenzentrum UNIX-Basis
Fritz Egger GmbH & Co.
Holzwerkstoffe
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
dirname-ng.pl
Description: dirname-ng.pl
- dirname - bug or feature?,
Fill Manuel <=