Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)

basename(1) OSS Shell and Utilities Reference Manual
NAME
basename - Returns specied parts of pathnames
SYNOPSIS
basename string [sufx]
DESCRIPTION
The basename command reads the string specied on the command line, deletes the portion
from the beginning to the last / (slash), and writes the base lename to standard output. If sufx
is specied on the command line and sufx appears in string, the string is returned with the sufx
removed.
The basename command is generally used inside command substitutions within a shell pro-
cedure to specify an output lename that is some variation of a specied input lename.
EXAMPLES
1. To display the base lename of a shell variable, enter:
basename $WORKFILE
This command displays the base lename of the value assigned to the WORKFILE
shell variable. If WORKFILE is set to /u/gabe/program.c, then program.c is
displayed.
2. To construct, in a shell script, a lename that is the same as another lename except for
its sufx, enter:
OFILE=basename $1 .c.o
This command assigns to OFILE the value of the rst positional parameter ($1), but
with its .c sufx changed to .o.If$1 is /u/jim/program.c, then OFILE becomes
program.o.
RELATED INFORMATION
Commands: dirname(1), sh(1).
128 Hewlett-Packard Company 527188-003