DIRNAME(1)

NAME
dirname - return the directory portion of pathname

SYNOPSIS
dirname string

DESCRIPTION
The string operand is treated as a pathname. It is converted to the name of the directory containing the filename corresponding to the last pathname component in string , performing the following actions in order:

1. If the string is empty (dirname ""), turn it into ".", skip to step 8.

2. Strip trailing slashes.

3. If the string is empty, turn it into "/", skip to step 8

4. Strip all non-slash trailing characters

5. If the string is empty, turn it into ".", skip to step 8

6. Strip trailing slashes.

7. If the string is empty, turn it into "/"

8. Write the resulting string to standard output.

OPTIONS
None. The option -- is not supported either.

OPERANDS

The following operand is supported:
    string A string.

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

"%s\n", <resulting string>

EXIT STATUS
The following exit values are returned:

0   Successful completion.

1   Missing argument.

CONSEQUENCES OF ERRORS
If an error is detected (dirname is called without arguments), output will not be written to standard output and the exit status will not be zero.

EXAMPLES
    Command Results

    dirname / /

    dirname // /

    dirname /a/b/ /a

    dirname //a//b// //a

    dirname ($? = 1)

    dirname a . ($? = 0)

    dirname "" . ($? = 0)

    dirname /a /

    dirname /a/b /a

    dirname a/b a

STANDARDS
The ASMIX dirname utility is expected to conform to The Open Group Single Unix 2 Commands and Utilities specification.

SEE ALSO
basename(1)