NAME
cd — change
working directory
SYNOPSIS
cd |
[directory] |
DESCRIPTION
The cd utility shall change the working
directory of the current shell execution environment; see 3.12. When invoked
with no operands, and the HOME environment variable is set
to a nonempty value, the directory named in the HOME
environment variable shall become the new working directory. If
HOME is empty or is undefined, the default behavior is
implementation defined.
OPTIONS
None.
OPERANDS
The following operands shall be supported by the implementation:
- directory
-
An absolute or relative pathname of the directory that becomes the new working directory. The interpretation of a relative pathname by
cddepends on the CDPATH environment variable. If directory is −, the results are implementation defined.
STANDARD INPUT
None.
INPUT FILES
None.
ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of
cd:
CDPATH-
A colon-separated list of pathnames that refer to directories. If the directory operand does not begin with a slash (/) character, and the first component is not dot or dot-dot,
cdshall search for directory relative to each directory named in the CDPATH variable, in the order listed. The new working directory shall be set to the first matching directory found. An empty string in place of a directory pathname represents the current directory. If CDPATH is not set, it shall be treated as if it were an empty string. HOME-
The name of the home directory, used when no directory operand is specified.
LANG-
This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.
LC_ALL-
This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.
LC_CTYPE-
This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments).
LC_MESSAGES-
This variable shall determine the language in which messages should be written.
ASYNCHRONOUS EVENTS
Default.
STANDARD OUTPUT
If a nonempty directory name from CDPATH is used, an absolute pathname of the new working directory shall be written to the standard output as follows: "%s\n", <new directory> Otherwise, there shall be no output.
STANDARD ERROR
Used only for diagnostic messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The cd utility shall exit with one of the
following values:
CONSEQUENCES OF ERRORS
The working directory remains unchanged.
RATIONALE
EXAMPLES
Editor’s Note: A balloter requested that the following rationale be highlighted in the D11. 2 recirculation.
Since cd affects the current shell
execution environment, it is generally provided as a shell regular built-in.
If it is called in a subshell or separate utility execution environment,
such as one of the following:
( cd /tmp) nohup
cd find . -exec cd {} \;
it will not affect the working directory of the caller’s environment.
The use of the CDPATH was introduced in the System V shell. Its use is analogous to the use of the PATH variable in the shell. Earlier systems such as the BSD C-shell used a shell parameter cdpath for this purpose.
HISTORY OF DECISIONS MADE
A common extension when HOME is undefined is to
get the login directory from the user database for the invoking user. This
does not occur on System V implementations. Not included in this description
are the features from the KornShell such as setting
OLDPWD,
toggling current and previous directory ( cd
−), and the twooperand form of cd ( cd old
new). This standard does not specify the results of
cd
- or of calls with more than one operand. Since these extensions are mostly used
in interactive situations, they may be considered for
inclusion in POSIX. 2a. The result of
cd - and of using no arguments with
HOME unset or null have been made implementation defined
at the request of the POSIX. 6 security working group. The
setting of the PWD
variable was removed from earlier drafts, as it can be replaced by
$(pwd).