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

basename(1) OSS Shell and Utilities Reference Manual
NAME
basename - Returns specified parts of pathnames
SYNOPSIS
basename string [suffix]
DESCRIPTION
The basename command reads the string specified on the command line, deletes the portion
from the beginning to the last / (slash), and writes the base filename to standard output. If suffix
is specified 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 filename that is some variation of a specified input filename.
EXAMPLES
1. To display the base filename of a shell variable, enter:
basename $WORKFILE
This command displays the base filename 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 filename that is the same as another filename except for
its sufx, enter:
OFILE=‘basename $1 .c‘.o
This command assigns to OFILE the value of the first 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-021