O'Reilly logo

Mac OS X Tiger in a Nutshell by Jason McIntosh, Chuck Toporek, Chris Stone, Andy Lester

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

basename

Synopsis

basename pathname [suffix]
basename  [-s suffix] pathname
                     [...]

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. The suffix may also be specified with the -s option, in which case multiple paths may be passed and stripped. basename is typically invoked via command substitution ('..') to generate a filename. See also dirname .

Option

-s suffix

Removes suffix from the filename, if found.

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required