basename Command Purpose Returns the base file name of a string parameter. Syntax basename String [ Suffix ] Description The basename command reads the String parameter specified on the command line, deletes any prefix that ends with a / (slash), as well as any specified Suffix parameter, and writes the remaining base file name to standard output. The basename and dirname commands are generally used inside com- mand substitutions within a shell script to specify an output file name that is some variation of a specified input file name. Exit Status This command returns the following exit values: 0 Successful completion. >0 An error occurred. Examples 1. To display the base name of a shell variable, enter: basename $WORKFILE The command displays the base name of the value assigned to the shell variable WORKFILE. If the value of the WORKFILE variable is the /home/jim/program.c file, then the command displays program.c. 2. To construct a file name that is the same as another file name, except for its suffix, enter: OFILE=`basename $1 .c`.o This command assigns to the OFILE file the value of the first po- sitional parameter ($1), but with its .c suffix changed to .o. If $1 is the /home/jim/program.c file, OFILE becomes program.o. Because program.o is only a base file name, it identifies a file in the current directory. Note: The ` (grave accent) specifies command substitution. Implementation Specifics This command is part of Base Operating System (BOS) Runtime. Files /usr/bin/basename Contains the basename command. Related Information The dirname command, sh command.