xref: /dragonfly/usr.bin/basename/basename.1 (revision 0fe46dc6)
1.\" Copyright (c) 1990, 1993, 1994
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)basename.1	8.2 (Berkeley) 4/18/94
32.\" $FreeBSD: head/usr.bin/basename/basename.1 216370 2010-12-11 08:32:16Z joel $
33.\"
34.Dd April 18, 1994
35.Dt BASENAME 1
36.Os
37.Sh NAME
38.Nm basename ,
39.Nm dirname
40.Nd return filename or directory portion of pathname
41.Sh SYNOPSIS
42.Nm
43.Ar string
44.Op Ar suffix
45.Nm
46.Op Fl a
47.Op Fl s Ar suffix
48.Ar string
49.Op Ar ...
50.Nm dirname
51.Ar string
52.Op Ar ...
53.Sh DESCRIPTION
54The
55.Nm
56utility deletes any prefix ending with the last slash
57.Ql \&/
58character present in
59.Ar string
60(after first stripping trailing slashes),
61and a
62.Ar suffix ,
63if given.
64The
65.Ar suffix
66is not stripped if it is identical to the remaining characters in
67.Ar string .
68The resulting filename is written to the standard output.
69A non-existent suffix is ignored.
70If
71.Fl a
72is specified, then every argument is treated as a
73.Ar string
74as if
75.Nm
76were invoked with just one argument.
77If
78.Fl s
79is specified, then the
80.Ar suffix
81is taken as its argument, and all other arguments are treated as a
82.Ar string .
83.Pp
84The
85.Nm dirname
86utility deletes the filename portion, beginning
87with the last slash
88.Ql \&/
89character to the end of
90.Ar string
91(after first stripping trailing slashes),
92and writes the result to the standard output.
93.Sh EXIT STATUS
94.Ex -std basename dirname
95.Sh EXAMPLES
96.Nm
97together with
98.Ar -a
99interprets the second argument as a
100.Ar string
101and produces "foo" followed by "bar" for:
102.Pp
103.Dl basename -a /usr/bin/foo /sbin/bar
104.Pp
105Passing multiple arguments to
106.Nm dirname
107produces
108.Pa /usr/bin
109followed by
110.Pa /sbin
111.Pp
112.Dl dirname /usr/bin/foo /sbin/bar
113.Pp
114The following line sets the shell variable
115.Ev FOO
116to
117.Pa /usr/bin .
118.Pp
119.Dl FOO=`dirname /usr/bin/trail`
120.Sh SEE ALSO
121.Xr csh 1 ,
122.Xr sh 1 ,
123.Xr basename 3 ,
124.Xr dirname 3
125.Sh STANDARDS
126The
127.Nm
128and
129.Nm dirname
130utilities are expected to be
131.St -p1003.2
132compatible.
133