# POSIXly-correct mode

Yash behaves as defined in POSIX.1-2008, Shell & Utilities for the most part, but some functionalities disobey POSIX for usability. When full POSIX-conformance is needed, you can enable the POSIXly-correct mode to make yash obey POSIX as mush as possible.

If yash is started with the name “sh”, the POSIXly-correct mode is automatically enabled. The `-o posixly-correct` command-line option also enables the POSIXly-correct mode. After yash has been started, the POSIXly-correct mode can be enabled by executing the command string `set -o posixly-correct`.

When the POSIXly-correct mode is on, yash not only tries to obey the requirements by POSIX, but also treats as errors most conditions where the behavior is undefined or unspecified by POSIX. As a result, most yash-specific functionalities are disabled in the POSIXly-correct mode.

Below is the complete list of the behavioral differences between when yash is in the POSIXly-correct mode and when not. When the POSIXly-correct mode is enabled:

- Different initialization scripts are used.

- Global aliases are not substituted.

- Nested commands in a compound command must not be empty.

- Words expanded in a for loop are assigned as a global variable rather than a local.

- The first pattern in a case command cannot be `esac`.

- The `function` keyword cannot be used for function definition.

- Simple commands cannot assign to arrays.

- Changing the value of the `LC_CTYPE` variable after the shell has been initialized does not affect the shell’s locale.

- The `RANDOM` variable cannot be used to generate random numbers.

- Tilde expansion only expands `~` and `~username`.

- Parameter expansion cannot be nested. No indexes are allowed.

- The commands in a command substitution of the form `$(commands)` are parsed every time the substitution is executed.

- Fractional numbers cannot be used in arithmetic expansion.

- In a redirection to a file, if the pathname expansion yielded more than one or no pathname, it is not immediately treated as an error. Instead, the shell tries to treat the word before the expansion as a pathname.

- Socket redirection, here strings, pipe redirection, and process redirection cannot be used.

- When executing a simple command, failure in command search does not trigger execution of the `COMMAND_NOT_FOUND_HANDLER` variable.

- In command search, a regular built-in needs to have a corresponding external command for the built-in to be found.

- asynchronous commands ignore the SIGINT and SIGQUIT signals even when job control is active. The standard input of asynchronous commands is redirected to /dev/null if the shell is not interactive, regardless of whether job control is active or not.

- Some built-ins behave differently. Especially, some command-line options cannot be used.

- A non-interactive shell exits when a special built-in is given a syntactically wrong arguments or when an error occurs in assignment or redirection with a special built-in.

- An interactive shell does not execute the `PROMPT_COMMAND` variable before printing a prompt. The values of the `PS1`, `PS2`, and `PS4` variables are parsed differently.

- In mail checking, a notification message is printed if the file has been modified, regardless of whether the file is empty.