PWD(1POSIX)

πŸ’– PWD(1POSIX) β€” the POSIX Programmer's Manual, bestie edition πŸ’–

okay so first things first, this page lives in the POSIX Programmer's Manual, and there's a lil heads-up before we even get to the good stuff πŸ‘‡

🚨 PROLOG 🚨

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page for the deets on Linux behavior, fr), or honestly the interface might not even be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

pwd β€” return working directory name. that's it. that's the whole job. iconic behavior honestly πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

pwd [-L|-P]

🌸 DESCRIPTION 🌸

So the pwd utility shall write to standard output an absolute pathname of the current working directory. and ngl the key part: that pathname does not contain the filenames dot or dot-dot. no .. shenanigans, no . filler, we're keeping it clean ✨

πŸ‘‘ OPTIONS πŸ‘‘

First off, the pwd utility shall conform to the Base Definitions volume of POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines. (yes bestie, there are rules, we follow them.)

The following options shall be supported by the implementation:

  • -L β€” If the PWD environment variable contains an absolute pathname of the current directory and that pathname doesn't contain any components that are dot or dot-dot, pwd shall write this pathname to standard output. EXCEPT (and this is the spicy caveat 🌢️): if the PWD environment variable is longer than {PATH_MAX} bytes including the terminating null, it is unspecified whether pwd writes this pathname to standard output or behaves as if the -P option had been specified. Otherwise, the -L option shall behave as the -P option.
  • -P β€” The pathname written to standard output shall not contain any components that refer to files of type symbolic link. If there are multiple pathnames that the pwd utility could write to standard output β€” one beginning with a single <slash> character and one or more beginning with two <slash> characters β€” then it shall write the pathname beginning with a single <slash> character. The pathname shall not contain any unnecessary <slash> characters after the leading one or two <slash> characters. periodt.

Now the tiebreaker tea β˜•: if both -L and -P are specified, the last one shall apply. And if neither -L nor -P is specified, the pwd utility shall behave as if -L had been specified. (so -L is the default, she's the main character πŸ’…)

🌈 OPERANDS 🌈

None. nothing. zero. empty plate. 🍽️

πŸ’€ STDIN πŸ’€

Not used. not even a little bit.

πŸŽ€ INPUT FILES πŸŽ€

None.

πŸ’œ ENVIRONMENT VARIABLES πŸ’œ

The following environment variables shall affect the execution of pwd:

  • LANG β€” Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1‐2017, Section 8.2, Internationalization Variables the precedence of internationalization variables used to determine the values of locale categories.) yes the sentence is long, i didn't write it, i just deliver it 🫢
  • LC_ALL β€” If set to a non-empty string value, override the values of all the other internationalization variables. she's the boss of the group chat.
  • LC_MESSAGES β€” Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
  • NLSPATH β€” Determine the location of message catalogs for the processing of LC_MESSAGES.
  • PWD β€” An absolute pathname of the current working directory. ⚠️ If an application sets or unsets the value of PWD, the behavior of pwd is unspecified. do not do this bestie, i'm begging.

🌟 ASYNCHRONOUS EVENTS 🌟

Default. she's chill.

⭐ STDOUT ⭐

The pwd utility output is an absolute pathname of the current working directory:

"%s\n", <directory pathname>

🩹 STDERR 🩹

The standard error shall be used only for diagnostic messages. she has one job and she does it.

🧚 OUTPUT FILES 🧚

None.

πŸ“ EXTENDED DESCRIPTION πŸ“

None.

πŸ”₯ EXIT STATUS πŸ”₯

The following exit values shall be returned:

  • 0 β€” Successful completion. we love a win πŸ’–
  • >0 β€” An error occurred. 😭

πŸ’… CONSEQUENCES OF ERRORS πŸ’…

If an error is detected, output shall not be written to standard output, a diagnostic message shall be written to standard error, and the exit status is not zero.

🚨 okay this part matters a LOT: no partial output. zero. none. the whole thing fails clean, not messy.

The following sections are informative. (translation: the drama is over, this is just lore now πŸ“–)

πŸ’™ APPLICATION USAGE πŸ’™

If the pathname obtained from pwd is longer than {PATH_MAX} bytes, it could produce an error if passed to cd. So therefore, in order to return to that directory it may be necessary to break the pathname into sections shorter than {PATH_MAX} and call cd on each section in turn β€” the first section being an absolute pathname and subsequent sections being relative pathnames. yes bestie, chop it up like a friendship bracelet πŸŽ€

πŸ¦„ EXAMPLES πŸ¦„

None.

πŸ‘‘ RATIONALE πŸ‘‘

Some implementations have historically provided pwd as a shell special built-in command. (lore πŸ•°οΈ)

In most utilities, if an error occurs, partial output may be written to standard output. This does not happen in historical implementations of pwd. Because pwd is frequently used in historical shell scripts without checking the exit status, it is important that the historical behavior is required here; therefore, the CONSEQUENCES OF ERRORS section specifically disallows any partial output being written to standard output. see?? told you it mattered.

An earlier version of this standard stated that the PWD environment variable was affected when the -P option was in effect. This was incorrect; conforming implementations do not do this. so if you heard that rumor, it was fake news, my bad for the old standard πŸ™ˆ

🌈 FUTURE DIRECTIONS 🌈

None.

πŸ”— SEE ALSO πŸ”—

  • cd
  • The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
  • The System Interfaces volume of POSIX.1‐2017, getcwd()

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie!! πŸ’– brought to you by IEEE/The Open Group, 2017 β€” the actual authors of this masterpiece, not me, i'm just the messenger with better vibes ✨ mwah, go run pwd and feel something 🫢

πŸ“¦ where this page comes from