Description: This page describes the behavior of yash's POSIXly-correct mode.

# POSIXly-correct mode

Yash behaves as defined in POSIX.1-2024, 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 much 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.

- If the shell was started with the `-c` option, `sh -c` (instead of `yash -c`) is printed as the script pathname on a syntax error.

- Global aliases are not substituted.

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

- The for loop iteration variable is created as global, regardless of the for-local shell option. The variable must have a portable (ASCII-only) name.

- The `;|` and `;;&` terminators cannot be used in a case command.

- The `!` keyword cannot be followed by `(` without any whitespaces in-between.

- The double-bracket command cannot be used.

- The `function` keyword cannot be used for function definition. The function must have a portable (ASCII-only) name.

- 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.

- The `LINENO`, `OLDPWD`, `OPTARG`, `OPTIND`, and `PWD` variables cannot be made readonly.

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

- Parameter expansion cannot be nested. No indexes or modifiers with word2 are allowed.

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

- In arithmetic expansion, fractional numbers and the `++` and `--` operators cannot be used. All variables must be numeric.

- The operand of a redirection cannot be the integer prefix to a next redirection operator.

- A compound command with a redirection cannot be immediately followed by a keyword like `}` and `fi`.

- In a redirection to a file, if the pathname expansion yields no pathname, it is not immediately treated as an error. Instead, the shell tries to proceed as if the pathname expansion did not occur.

- A file descriptor must be readable and writable when duplicated by the `<&` and `>&` redirection operator, respectively.

- 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.

- Elective and extension built-ins cannot be executed.

- Some built-ins behave differently. Especially, long command-line options (as well as some others) 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` or `POST_PROMPT_COMMAND` variable before and after a prompt, respectively. The values of the `PS1`, `PS2`, and `PS4` variables are parsed differently. Prompt variables with a `YASH_` prefix (e.g. `YASH_PS1`) are not used.

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