dirname operates on a single string argument, and sends it's output
to standard out. dirname's output can be redirected, but
redirecting to dirname's standard in is in effect an alias for /dev/null.
string_argument may be subject to shell expansion or may be a
variable. However, any expansion must result in a single argument.
If
string_argument
is a single component, that is, if it contains no slashes,
dirname
prints `.' to imply "the current directory". dirname doesn't care if
string_argument actually happens to be a file, it is simply dealing
with the name as a string. If string_argument ends with a /, the
last part including the trailing slash is removed. This means that dirname
returns "the pathname of the directory containing it's argument", even if
it's argument is a directory, and without any actual filesystem
intelligence, but rather in terms of what the resulting string
manipulations look like.
$ dirname sumutha/pathname-like/string/ocrudeu/
$ dirname aDoseOfNoSlashitol
sumutha/pathname-like/string
.GNU Options
SEE ALSO
dirname is roughly the opposite of
basename .
Completely general truncating and otherwise modifying strings can be
done with
sed or
awk . Both are complete,
but scriptable and pipeable programming languages, but with some
syntactic overhead compared to a simple utility like dirname. One could
also use
tr
to change a
delimiter in a string to or from a slash,
which along with dirname,
basename and also
cut ,
gives a fairly general set of string operators directly from the shell.
RIGHTS
dirname in cLIeNUX is from the GNU shell utilities, and is subject to the
GNU GPL. This seedoc contains a few snippets of the GNU manpage, but is
not a derived work of it or anything else, and is
Copyright 1999 Richard Allen Hohensee. This page is released for
redistribution only as part of an intact and entire cLIeNUX Core.