1PWD(1P)                    POSIX Programmer's Manual                   PWD(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       pwd — return working directory name
13

SYNOPSIS

15       pwd [-L|-P]
16

DESCRIPTION

18       The pwd utility shall write to standard output an absolute pathname  of
19       the current working directory, which does not contain the filenames dot
20       or dot-dot.
21

OPTIONS

23       The pwd utility  shall  conform  to  the  Base  Definitions  volume  of
24       POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
25
26       The following options shall be supported by the implementation:
27
28       -L        If the PWD environment variable contains an absolute pathname
29                 of the current directory and the pathname  does  not  contain
30                 any  components that are dot or dot-dot, pwd shall write this
31                 pathname to standard output, except that if the PWD  environ‐
32                 ment  variable  is longer than {PATH_MAX} bytes including the
33                 terminating null, it is unspecified whether pwd  writes  this
34                 pathname  to  standard  output or behaves as if the -P option
35                 had been specified. Otherwise, the -L option shall behave  as
36                 the -P option.
37
38       -P        The pathname written to standard output shall not contain any
39                 components that refer to files  of  type  symbolic  link.  If
40                 there are multiple pathnames that the pwd utility could write
41                 to standard output, one beginning with a single <slash> char‐
42                 acter  and one or more beginning with two <slash> characters,
43                 then it shall write the  pathname  beginning  with  a  single
44                 <slash>  character. The pathname shall not contain any unnec‐
45                 essary <slash>  characters  after  the  leading  one  or  two
46                 <slash> characters.
47
48       If  both  -L and -P are specified, the last one shall apply. If neither
49       -L nor -P is specified, the pwd utility shall behave as if -L had  been
50       specified.
51

OPERANDS

53       None.
54

STDIN

56       Not used.
57

INPUT FILES

59       None.
60

ENVIRONMENT VARIABLES

62       The following environment variables shall affect the execution of pwd:
63
64       LANG      Provide  a  default  value for the internationalization vari‐
65                 ables that are unset or null. (See the Base Definitions  vol‐
66                 ume  of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
67                 ables the precedence of internationalization  variables  used
68                 to determine the values of locale categories.)
69
70       LC_ALL    If  set  to  a non-empty string value, override the values of
71                 all the other internationalization variables.
72
73       LC_MESSAGES
74                 Determine the locale that should be used to affect the format
75                 and  contents  of  diagnostic  messages  written  to standard
76                 error.
77
78       NLSPATH   Determine the location of message catalogs for the processing
79                 of LC_MESSAGES.
80
81       PWD       An  absolute pathname of the current working directory. If an
82                 application sets or unsets the value of PWD, the behavior  of
83                 pwd is unspecified.
84

ASYNCHRONOUS EVENTS

86       Default.
87

STDOUT

89       The  pwd  utility output is an absolute pathname of the current working
90       directory:
91
92
93           "%s\n", <directory pathname>
94

STDERR

96       The standard error shall be used only for diagnostic messages.
97

OUTPUT FILES

99       None.
100

EXTENDED DESCRIPTION

102       None.
103

EXIT STATUS

105       The following exit values shall be returned:
106
107        0    Successful completion.
108
109       >0    An error occurred.
110

CONSEQUENCES OF ERRORS

112       If an error is detected, output shall not be written to  standard  out‐
113       put,  a  diagnostic message shall be written to standard error, and the
114       exit status is not zero.
115
116       The following sections are informative.
117

APPLICATION USAGE

119       If the pathname obtained from pwd is longer than {PATH_MAX}  bytes,  it
120       could  produce an error if passed to cd.  Therefore, in order to return
121       to that directory it may be necessary to break the pathname  into  sec‐
122       tions  shorter than {PATH_MAX} and call cd on each section in turn (the
123       first section being an absolute pathname and subsequent sections  being
124       relative pathnames).
125

EXAMPLES

127       None.
128

RATIONALE

130       Some  implementations have historically provided pwd as a shell special
131       built-in command.
132
133       In most utilities, if an error occurs, partial output may be written to
134       standard  output. This does not happen in historical implementations of
135       pwd.  Because pwd is frequently used in historical shell scripts  with‐
136       out  checking  the  exit  status,  it  is important that the historical
137       behavior is required here; therefore, the CONSEQUENCES OF  ERRORS  sec‐
138       tion  specifically  disallows any partial output being written to stan‐
139       dard output.
140
141       An earlier version of this standard stated  that  the  PWD  environment
142       variable was affected when the -P option was in effect. This was incor‐
143       rect; conforming implementations do not do this.
144

FUTURE DIRECTIONS

146       None.
147

SEE ALSO

149       cd
150
151       The Base Definitions volume of  POSIX.1‐2017,  Chapter  8,  Environment
152       Variables, Section 12.2, Utility Syntax Guidelines
153
154       The System Interfaces volume of POSIX.1‐2017, getcwd()
155
157       Portions  of  this text are reprinted and reproduced in electronic form
158       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
159       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
160       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
161       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
162       event of any discrepancy between this version and the original IEEE and
163       The  Open Group Standard, the original IEEE and The Open Group Standard
164       is the referee document. The original Standard can be  obtained  online
165       at http://www.opengroup.org/unix/online.html .
166
167       Any  typographical  or  formatting  errors that appear in this page are
168       most likely to have been introduced during the conversion of the source
169       files  to  man page format. To report such errors, see https://www.ker
170       nel.org/doc/man-pages/reporting_bugs.html .
171
172
173
174IEEE/The Open Group                  2017                              PWD(1P)
Impressum