1basename(1)                      User Commands                     basename(1)
2
3
4

NAME

6       basename, dirname - deliver portions of path names
7

SYNOPSIS

9       /usr/bin/basename string [suffix]
10
11
12       /usr/xpg4/bin/basename string [suffix]
13
14
15       dirname string
16
17

DESCRIPTION

19       The  basename utility deletes any prefix ending in / and the suffix (if
20       present in string) from string, and prints the result on  the  standard
21       output. It is normally used inside substitution marks (``) within shell
22       procedures.
23
24   /usr/bin
25       The suffix is a pattern defined on the expr(1) manual page.
26
27   /usr/xpg4/bin
28       The suffix is a string with no special significance attached to  any of
29       the characters it contains.
30
31
32       The dirname utility delivers all but the last level of the path name in
33       string.
34

EXAMPLES

36       Example 1 Setting environment variables
37
38
39       The  following  example,  invoked  with  the  argument   /home/sms/per‐
40       sonal/mail  sets  the  environment variable NAME to the file named mail
41       and the environment variable MYMAILPATH to the  string   /home/sms/per‐
42       sonal:
43
44
45         example% NAME=`basename $HOME/personal/mail`
46         example% MYMAILPATH=`dirname $HOME/personal/mail`
47
48
49
50       Example 2 Compiling a file and moving the output
51
52
53       This  shell  procedure,  invoked  with the argument /usr/src/bin/cat.c,
54       compiles the named file and moves the output  to  cat  in  the  current
55       directory:
56
57
58         example% cc $1
59         example% mv a.out `basename $1 .c`
60
61
62

ENVIRONMENT VARIABLES

64       See  environ(5) for descriptions of the following environment variables
65       that affect  the execution  of  basename  and  dirname:  LANG,  LC_ALL,
66       LC_CTYPE, LC_MESSAGES, and NLSPATH.
67

EXIT STATUS

69       The following exit values are returned:
70
71       0     Successful completion.
72
73
74       >0    An error occurred.
75
76

ATTRIBUTES

78       See attributes(5) for descriptions of the following attributes:
79
80   /usr/bin
81       ┌─────────────────────────────┬─────────────────────────────┐
82       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
83       ├─────────────────────────────┼─────────────────────────────┤
84       │Availability                 │SUNWcsu                      │
85       └─────────────────────────────┴─────────────────────────────┘
86
87   /usr/xpg4/bin
88       ┌─────────────────────────────┬─────────────────────────────┐
89       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
90       ├─────────────────────────────┼─────────────────────────────┤
91       │Availability                 │SUNWxcu4                     │
92       ├─────────────────────────────┼─────────────────────────────┤
93       │Interface Stability          │Standard                     │
94       └─────────────────────────────┴─────────────────────────────┘
95

SEE ALSO

97       expr(1), basename(3C), attributes(5), environ(5), standards(5)
98
99
100
101SunOS 5.11                        18 Mar 1997                      basename(1)
Impressum