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:
- If string is // , skip steps 2 to 5.
- If string consists entirely of slash characters, string will be set to a single slash character. In this case, skip steps 3 to 8.
- If there are any trailing slash characters in string , they will be removed.
- 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.
- If there are any trailing non-slash characters in string , they will be removed.
- If the remaining string is // , it is implementation-dependent whether steps 7 and 8 are skipped or processed.
- If there are any trailing slash characters in string , they will be removed.
- 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
LANGis 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:
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(1) , Parameters and Variables .