DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

dirname(C)


dirname -- deliver directory part of pathname

Syntax

dirname string

Description

The dirname command delivers all but the last component of the pathname in string and prints the result on the standard output. If there is only one component in the pathname, only a ``dot'' is printed. If string consists entirely of slash characters, a single slash is printed. However, if string consists of only two slashes, both are printed. It is normally used inside substitution marks (``) within shell procedures.

The companion command basename deletes any prefix ending in a slash (/) and the suffix (if present in string) from string, and prints the result on the standard output.

Exit values

dirname returns the following values:

0
successful completion

>0
an error occurred

Examples

The following example sets the shell variable NAME to /usr/src/cmd:

NAME=`dirname /usr/src/cmd/cat.c`

This example prints /a/b/c on the standard output:

dirname /a/b/c/d

This example prints a ``dot'' on the standard output:

dirname file.ext

This example moves to the location of a file being searched for (lostfile):

cd `find . -name lostfile -exec dirname {} \;`

See also

basename(C), sh(C)

Standards conformance

dirname is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003