cd

change working directory

KornShell Built-in


SYNOPSIS

cd [directory]

cd old new

cd -


DESCRIPTION

The command
cd directory
changes the working directory of the current KornShell execution environment (see sh) to directory. If directory is an absolute path name, beginning with /, this is the target directory. If directory is a relative path name, cd assumes it is relative to the current working directory.

In the KornShell, if the variable CDPATH is defined, the built-in cd command searches for a relative path name under each of the directories defined in CDPATH. If cd finds the directory outside the current working directory, it displays the new working directory.

Use colons to separate directories in CDPATH. In CDPATH, a null string represents the current directory. For example, if the value of CDPATH begins with a separator character, cd searches the current directory first; if it ends with a separator character, cd searches the current directory last.

In the MKS KornShell, the command
cd -
is a special case that changes the working directory to the previous working directory by exchanging the values of the variables PWD and OLDPWD.
Note:

Repeating this command toggles the current working directory between the current and old working directory.

Calling cd without arguments sets the working directory to the value of the HOME environment variable, if the variable exists. If there is no HOME variable, cd does not change the current directory.

The form
cd old new
is an extension to traditional KornShell implementations. The shell keeps the name of the current directory in the variable PWD. The cd command scans the current value of PWD and replaces the first occurrence of the string old with the string new. The shell displays the resulting value of PWD and it becomes the new working directory.


ENVIRONMENT VARIABLES

CDPATH

contains a list of directories for cd to search under when directory is a relative path name.

HOME

contains the name of your home directory. This is used when you do not specify directory on the command line.

OLDPWD

contains the path name of the previous working directory. This is used by cd -.

PWD

contains the path name of the current working directory. This is set by cd after changing to that directory.


DIAGNOSTICS

Possible exit status values are:
0

Successful completion.

1

Failure due to any of the following:

— no HOME directory
— no previous directory
— a search for directory failed
— an old/new substitution failed
2

An invalid command line option.

Messages

"dir" bad directory

cd was unable to locate the target directory. This does not change the working directory.

Restricted

You are using the restricted version of the KornShell (for example, by specifying the -r option for sh). The restricted shell does not allow the cd command.

No HOME directory

You have not assigned a value to the HOME environment variable. Thus when you say cd to return to your home directory, cd cannot figure out what your home directory is.

No previous directory

You tried the command cd - to return to your previous directory, but there is no record of your previous directory.

Pattern "old" not found in "dir"

You tried a command of the form

cd old new
However, the name of the current directory dir does not contain any string matching the regular expression old.


PORTABILITY

POSIX.2. x/OPEN Portability Guide 4.0.

All UNIX systems feature the first form of the command.

In the MKS Toolkit implementation of this command, all forms are built into the MKS KornShell.

The cd old new form of the command is an extension to the POSIX standard.


SEE ALSO

Commands:
set sh


Updated MKS Toolkit [3khat16.ico]HP3000 [3khat16.ico]3kMail [archive16.gif]