Name

basename

Synopsis

basename pathname [suffix]

Given a pathname, strips the path prefix and leaves just the filename, which is printed on standard output. If specified, a filename suffix (e.g., .c) is removed also. basename is typically invoked via command substitution ('...') to generate a filename. See also dirname.

Example

Given the following fragment from a Bourne shell script:

ofile=output_file
myname="`basename $0`"
echo "$myname: QUITTING: can't open $ofile" 1>&2
exit 1

If the script is called do_it, the following message is printed on standard error:

do_it: QUITTING: can't open output_file

Get Mac OS X Panther in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.