DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

basename(C)


basename -- remove directory names from pathnames

Syntax

basename string [ suffix ]

Description

The basename command deletes any prefix ending in ``/'' and the suffix (if present in string) from string, and prints the result on the standard output. The result is the ``base'' name of the file, that is, the filename without any preceding directory path and without an extension. It is used inside substitution marks (` `) in shell procedures to construct new filenames.

Note that the suffix is not deleted if it is identical to the resulting basename.

The related command dirname deletes the last level from string and prints the resulting path on the standard output.

Exit values

basename returns the following values:

0
successful completion

>0
an error occurred

Examples

The following command displays the filename memos on the standard output:

basename /usr/johnh/memos.old .old

The following shell procedure, when invoked with the argument /usr/src/cmd/cat.c, compiles the named file and moves the output to a file named cat in the current directory:

   cc $1
   mv a.out `basename $1 .c`

See also

dirname(C), sh(C)

Standards conformance

basename is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003