b
basename(1) | basename(1) |
NAME
basename, dirname - extract portions of path names
SYNOPSIS
basename string [ suf®x ]
dirname [ string ]
DESCRIPTION
basename deletes any pre®x ending in / and the suf®x (if present in string) from string, and prints the result on the standard output. If string consists entirely of slash characters, string is set to a single slash character. If there are any trailing slash characters in string, they are removed. If the suf®x operand is present but not identical to the characters remaining in string, but it is identical to a suf®x of the characters remaining in string, the suf®x is removed from string. basename is normally used inside command substitution marks ( Á...Á ) within shell procedures.
dirname delivers all but the last level of the path name in string. If string does not contain a directory component, dirname returns ., indicating the current working directory.
EXTERNAL INFLUENCES
Environment Variables
LC_CTYPE determines the interpretation of string and, in the case of basename, suf®x as single and/or
If LC_CTYPE is not speci®ed in the environment or is set to the empty string, the value of LANG is used as a default for each unspeci®ed or empty variable. If LANG is not speci®ed or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, basename and dirname behave as if all internationalization variables are set to "C". See environ(5).
International Code Set Support
Single- and
EXAMPLES
The following shell script, invoked with the argument /usr/src/cmd/cat.c, compiles the named ®le and moves the output to a ®le named cat in the current directory:
cc $1
mv a.out `basename $1 .c`
The following example sets the shell variable NAME to /usr/src/cmd :
NAME=`dirname /usr/src/cmd/cat.c`
RETURNS
basename and dirname return one of the following values:
0Successful completion.
1Incorrect number of
SEE ALSO expr(1), sh(1).
STANDARDS CONFORMANCE
basename: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
dirname: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
Section 1−40 | − 1 − |