chdir-home 1 user commands nosh
chdir-home change working directory to the home directory then chain
`chdir-home` --oknodir next-prog

## Description

`chdir-home` is a chain-loading utility that changes its working directory to the value of the `HOME` environment variable, like the shell built-in `chdir` command when given no arguments, and then chain loads to next-prog with the execvp 3 function.

`chdir-home` places no requirement on the value of the `HOME` environment variable and uses that value exactly as it stands. It should be an absolute pathname; but a relative pathname is not regarded as an error.

next-prog may contain its own command line options, which `chdir-home` will ignore.

If the home directory cannot be changed to, normally `chdir-home` exits with a non-zero exit status does not chain. Using the --oknodir command-line option causes it to change working directory to the `/` directory instead and to carry on, akin to the behaviours of login 1 programs when a user's home directory is unavailable.

The `/` directory is a "safe" choice for a default home directory inasmuch as it is not expected to contain any "dotfiles" that programs may mistakenly access as if they were in a bona fide home directory. Historically, `/` actually was the superuser's own home directory, and this would have not been a "safe" choice; but for security reasons the convention changed to the superuser having a distinct home directory (on the root volume) as `/root` or some such and `/` is nowadays no longer a bona fide home directory.

Unlike the shell built-in `chdir` command, `chdir-home` always operates in "physical" mode, and performs no canonicalization of `..` or `.` components. For the benefit of the pwd 1 command when its -L command-line option is used, if the path of the directory changed to is an absolute one `chdir-home` sets the `PWD` environment variable to that path, and unsets that environment variable if it is a relative path.

Also unlike the shell built-in `chdir` command, `chdir-home` ignores any `CDPATH` environment variable, and performs no interpolation for leading `~` characters.

## See also

chdir 1

  a chain-loading command that takes an explicit directory name

userenv 1
userenv-fromenv 1

  chain-loading commands that specifically set the `HOME` environment variable

## Author

Jonathan de Boyne Pollard