basename - Return the nondirectory components of a path name
Format
basename name [suffix]
Description
basename strips
off the leading part of a path name, leaving only the final component
of the name, which is assumed to be the file name. To accomplish this, basename first
checks to see if name consists of nothing
but slash (/
) characters. If so, basename replaces name with
a single slash and the process is complete. If not, basename removes
trailing slashes. If slashes still remain, basename strips
off all leading characters up to and including the final slash. Finally,
if you specify suffix and the remaining
portion of name contains a suffix that matches suffix, basename removes
that suffix.
Examples
The command:
basename src/dos/printf.c
produces: printf.c
Localization
basename uses
the following localization environment variables:
- LANG
- LC_ALL
- LC_CTYPE
- LC_MESSAGES
- NLSPATH
Exit values
0
- Successful completion.
1
- Failure due to any of the following reasons:
- Unknown command-line option.
- Incorrect number of arguments.
Portability
POSIX.2, X/Open Portability Guide, UNIX systems.
Related information
dirname