Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

basename(1) [ultrix man page]

basename(1)						      General Commands Manual						       basename(1)

Name
       basename - strip directory names from pathname

Syntax
       basename string [ suffix ]

Description
       The  command  deletes from string any prefix up to and including the last slash (/) and the suffix (if specified), and prints the result on
       the standard output.  The command handles limited regular expressions in the same manner as metacharacters must	be  escaped  if  they  are
       intended to be interpreted literally.  For example:
       % basename /vmunix .x
       vmun
       % basename /vmunix '.x'
       vmunix
       In  the	first example, returns because it interprets the as a regular expression consisting of any character followed by the letter In the
       second example, the dot is escaped; there is no match on a dot followed by and returns

       The command is often used inside substitution marks (` `) within shell procedures.

Examples
       The following example shell script compiles the file and moves the output to in the current directory:
       cc /usr/src/bin/cat.c
       mv a.out `basename $1 .c`
       The following example echoes only the base name of the file by removing the prefix and any possible sequence of	characters  following  the
       period in the file's name:
       % basename /etc/syslog.conf '..*'
       syslog

See Also
       dirname(1), ex(1), sh(1)

																       basename(1)

Check Out this Related Man Page

basename(1)							   User Commands						       basename(1)

NAME
basename, dirname - deliver portions of path names SYNOPSIS
/usr/bin/basename string [suffix] /usr/xpg4/bin/basename string [suffix] dirname string DESCRIPTION
The basename utility deletes any prefix ending in / and the suffix (if present in string) from string, and prints the result on the stan- dard output. It is normally used inside substitution marks (``) within shell procedures. /usr/bin The suffix is a pattern defined on the expr(1) manual page. /usr/xpg4/bin The suffix is a string with no special significance attached to any of the characters it contains. The dirname utility delivers all but the last level of the path name in string. EXAMPLES
Example 1 Setting environment variables The following example, invoked with the argument /home/sms/personal/mail sets the environment variable NAME to the file named mail and the environment variable MYMAILPATH to the string /home/sms/personal: example% NAME=`basename $HOME/personal/mail` example% MYMAILPATH=`dirname $HOME/personal/mail` Example 2 Compiling a file and moving the output This shell procedure, invoked with the argument /usr/src/bin/cat.c, compiles the named file and moves the output to cat in the current directory: example% cc $1 example% mv a.out `basename $1 .c` ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of basename and dirname: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ /usr/xpg4/bin +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
expr(1), basename(3C), attributes(5), environ(5), standards(5) SunOS 5.11 18 Mar 1997 basename(1)
Man Page