dirname - Return directory portion of path name
Synopsis
dirname string
Description
You can use dirname to delete the filename
portion, beginning with the last slash character (/) to the end of
string, and write the result to standard output. The
string is processed using the following rules:
- If string consists entirely of slash characters, a
single slash character is written to standard output and processing
ends.
- If there are any trailing slash characters in string,
they are removed.
- If there are no slash characters remaining in string,
a period character is written to standard output and processing
ends.
- If there are trailing non-slash characters in string,
they are removed.
- If there are any trailing slash characters in string,
they are removed.
- If the remaining string is empty, string is set to a
single slash character.
Operands
The string operand is the pathname of which
dirname will return the directory portion of.
Exit Status
- 0 on success
- >0 if an error occurs.
Related information
Examples
- Set the shell variable FOO to "/usr/bin".
FOO=$(dirname /usr/bin/trail)