basename, dirname — extract portions of path names
deletes any prefix ending in
(if present in
and prints the result on the standard output.
consists entirely of slash characters,
is set to a single slash character.
If there are any trailing slash characters in
they are removed.
If the suffix operand is present
but not identical to the characters remaining in
but it is identical to a suffix of the characters remaining in
the suffix is removed from
is normally used inside command substitution marks
within shell procedures.
delivers all but the last level of the path name in
does not contain a directory component,
indicating the current working directory.
determines the interpretation of string and, in the
case of basename, suffix as single and/or multi-byte characters.
is not specified in the environment or is set to
the empty string, the value of
is used as a default for each
unspecified or empty variable. If
is not specified or is
set to the empty string, a default of "C" (see
used instead of
If any internationalization variable
contains an invalid setting,
behave as if all internationalization variables are set to "C".
International Code Set Support
Single- and multi-byte character code sets are supported.
The following shell script, invoked with the argument
compiles the named file and moves the output to a file named
in the current directory:
mv a.out `basename $1 .c`
The following example sets the shell variable
return one of the following values:
Incorrect number of command-line arguments.
basename: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
dirname: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2