basename, dirname - Returns the base file name or directory portion of a path name
basename string [suffix]
Interfaces documented on this reference page conform to industry standards as follows:
basename: XPG4, XPG4-UNIX
dirname: XPG4, XPG4-UNIX
Refer to the
reference page for more information
about industry standards and associated tags.
A string to be evaluated. This string may be empty.
A file name suffix to be deleted if found. This operand applies
command only, and is optional.
The basename command reads the string specified on the command line, deletes the portion from the beginning to the last / (slash), and writes the base file name to standard output. If suffix is specified on the command line and suffix appears in string, the string is returned with the suffix removed.
The dirname command reads the string specified on the command line, deletes from the last / (slash) to the end of the line, and writes the remaining path name to standard output.
[Compaq] The basename and dirname commands are generally used inside command substitutions within a shell procedure to specify an output file name that is some variation of a specified input file name. For more information, see the csh(1), ksh(1), and sh(1b) or sh(1p) reference pages.
The following table demonstrates the processing applied to characters with particular meanings by the basename and dirname commands.
|<null>||err msg||err msg|
It is not an error if
is not a part
To display the base file name of a shell variable, enter: basename $WORKFILE
The following environment variables affect the execution of
Provides a default value for the internationalization variables
that are unset or null. If
is unset or null, the corresponding value from the default locale is used.
If any of the internationalization variables contain an invalid setting, the
utility behaves as if none of the variables had been defined.
If set to a non-empty string value, overrides the values of
all the other internationalization variables.
Determines the locale for the interpretation of sequences
of bytes of text data as characters (for example, single-byte as opposed to
multibyte characters in arguments).
Determines the locale for the format and contents of diagnostic
messages written to standard error.
Determines the location of message catalogues for the processing
Commands: csh(1), ksh(1), Bourne shell sh(1b), POSIX shell sh(1p)