The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

dirname - return the directory portion of pathname

 SYNOPSIS



dirname string

 DESCRIPTION

The string operand will be treated as a pathname, as defined in pathname (see the XBD specification, Glossary  ). The string string will be converted to the name of the directory containing the filename corresponding to the last pathname component in string, performing actions equivalent to the following steps in order:

  1. If string is //, skip steps 2 to 5.

  2. If string consists entirely of slash characters, string will be set to a single slash character. In this case, skip steps 3 to 8.

  3. If there are any trailing slash characters in string, they will be removed.

  4. If there are no slash characters remaining in string, string will be set to a single period character. In this case, skip steps 5 to 8.

  5. If there are any trailing non-slash characters in string, they will be removed.

  6. If the remaining string is //, it is implementation-dependent whether steps 7 and 8 are skipped or processed.

  7. If there are any trailing slash characters in string, they will be removed.

  8. If the remaining string is empty, string will be set to a single slash character.

The resulting string will be written to standard output.

 OPTIONS

None.

 OPERANDS

The following operand is supported:
string
A string.

 STDIN

Not used.

 INPUT FILES

None.

 ENVIRONMENT VARIABLES

The following environment variables affect the execution of dirname:
LANG
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES .

 ASYNCHRONOUS EVENTS

Default.

 STDOUT

The dirname utility will write a line to the standard output in the following format:

"%s\n", <resulting string>

 STDERR

Used only for diagnostic messages.

 OUTPUT FILES

None.

 EXTENDED DESCRIPTION

None.

 EXIT STATUS

The following exit values are returned:
0
Successful completion.
>0
An error occurred.

 CONSEQUENCES OF ERRORS

Default.

 APPLICATION USAGE

The definition of pathname specifies implementation-dependent behaviour for pathnames starting with two slash characters. Therefore, applications must not arbitrarily add slashes to the beginning of a pathname unless they can ensure that there are more or less than two or are prepared to deal with the implementation-dependent consequences.

 EXAMPLES

Command Results
dirname / /
dirname // / or //
dirname /a/b/ /a
dirname //a//b// //a
dirname unspecified
dirname a . ($? = 0)
dirname "" . ($? = 0)
dirname /a /
dirname /a/b /a
dirname a/b a

 FUTURE DIRECTIONS

None.

 SEE ALSO

basename, Parameters and Variables .

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]