'\"macro stdmacro
.if n .pH g1.basename @(#)basename	40.5 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} basename 1 "User Environment Utilities" "\&"
.if \nX=1 .ds x} basename 1 "User Environment Utilities"
.if \nX=2 .ds x} basename 1 "" "\&"
.if \nX=3 .ds x} basename "" "" "\&"
.TH \*(x}
.if t .ds ' \h@.05m@\s+4\v@.333m@\'\v@-.333m@\s-4\h@.05m@
.if n .ds ' '
.if t .ds ` \h@.05m@\s+4\v@.333m@\`\v@-.333m@\s-4\h@.05m@
.if n .ds ` `
.SH NAME
\f4basename\f1, \f4dirname\f1 \- deliver portions of path names
.SH SYNOPSIS
\f4basename\f1
.I string
[
.I suffix
]
.br
\f4dirname\f1
.I string
.SH DESCRIPTION
\f4basename\fP
deletes any prefix ending in
\f4/\f1
and the
.I suffix\^
(if present in
.IR string )
from
.IR string ,
and prints the result on the standard output.
It is normally used inside substitution marks
\f1(\f4\*`\|\*`\f1)
within shell procedures.
The \f2suffix\fP is a pattern as defined on the \f4ed\fP(1) manual
page.
.PP
\f4dirname\fP
delivers all but the last level of the path name in
.IR string .
.SH EXAMPLES
The following example, invoked with the argument
\f4/home/sms/personal/mail\f1
sets the environment variable
\f4NAME\f1
to the file named
\f4mail\f1
and the environment variable
\f4MYMAILPATH\f1
to the string 
\f4/home/sms/personal\f1.
.PP
.RS
.ft 4
.nf
NAME=\*`basename \|$HOME/personal/mail\*`
MYMAILPATH=\*`dirname \|$HOME/personal/mail\*`
.fi
.ft 1
.RE
.P
This shell procedure, invoked with the argument
\f4/usr/src/bin/cat.c\fP,
compiles the named file and moves the output to
\f4cat\fP
in the current directory:
.RS
.sp .5
.nf
\f4cc $1\f1
\f4mv a.out \`basename $1 .c\`\f1
.fi
.RE
.SH SEE ALSO
\f4ed\fP(1),
\f4sh\fP(1).
.\"	@(#)basename.1	6.2 of 9/2/83
.Ee
