= POSIXly-correct mode
:encoding: UTF-8
:lang: en
//:title: Yash manual - POSIXly-correct mode
:description: This page describes the behavior of yash's POSIXly-correct mode.

Yash behaves as defined in
link:http://pubs.opengroup.org/onlinepubs/9699919799/[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 dfn:[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 +link:_set.html[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 link:invoke.html#init[initialization scripts] are used.
- If the shell was started with the link:invoke.html#arguments[+-c+ option],
  +sh -c+ (instead of +yash -c+) is printed as the script pathname on a syntax
  error.
- Global link:syntax.html#aliases[aliases] are not substituted.
- Nested commands in a link:syntax.html#compound[compound command] must not be
  empty.
- The link:syntax.html#for[for loop] iteration variable is created as global,
  regardless of the link:_set.html#so-forlocal[for-local] shell option.
  The variable must have a portable (ASCII-only) name.
- The first pattern in a link:syntax.html#case[case command] cannot be +esac+.
- The +!+ keyword cannot be followed by +(+ without any whitespaces
  in-between.
- The link:syntax.html#double-bracket[double-bracket command] cannot be used.
- The +function+ keyword cannot be used for link:syntax.html#funcdef[function
  definition]. The function must have a portable (ASCII-only) name.
- link:syntax.html#simple[Simple commands] cannot assign to
  link:params.html#arrays[arrays].
- Changing the value of the link:params.html#sv-lc_ctype[+LC_CTYPE+ variable]
  after the shell has been initialized does not affect the shell's locale.
- The link:params.html#sv-random[+RANDOM+ variable] cannot be used to generate
  random numbers.
- link:expand.html#tilde[Tilde expansion] only expands +~+ and
  +~{{username}}+.
- link:expand.html#params[Parameter expansion] cannot be nested.
  No link:expand.html#param-index[indexes] or
  link:expand.html#param-mod[modifiers] with {{word2}} are allowed.
- The commands in a link:expand.html#cmdsub[command substitution] of the form
  +$({{commands}})+ are parsed every time the substitution is executed.
- In link:expand.html#arith[arithmetic expansion], fractional numbers and the
  `++` and `--` operators cannot be used. All variables must be numeric.
- The operand of a link:redir.html[redirection] cannot be the integer prefix
  to a next redirection operator.
- A link:syntax.html#compound[compound command] with a
  link:redir.html[redirection] cannot be immediately followed by a keyword
  like +}+ and +fi+.
- In a link:redir.html#file[redirection to a file], if the
  link:expand.html#glob[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.
- A file descriptor must be readable and writable when duplicated by the
  +&lt;&amp;+ and +&gt;&amp;+ link:redir.html#dup[redirection] operator,
  respectively.
- link:redir.html#socket[Socket redirection], link:redir.html#here[here
  strings], link:redir.html#pipe[pipe redirection], and
  link:redir.html#process[process redirection] cannot be used.
- When link:exec.html#simple[executing a simple command], failure in command
  search does not trigger execution of the
  link:params.html#sv-command_not_found_handler[+COMMAND_NOT_FOUND_HANDLER+
  variable].
- link:builtin.html#types[Elective and extension built-ins] cannot be executed.
- Some link:builtin.html[built-ins] behave differently.
  Especially, long command-line options (as well as some others) cannot be
  used.
- A link:interact.html[non-interactive] shell exits when a
  link:builtin.html#types[special built-in] is given a syntactically wrong
  arguments or when an error occurs in assignment or redirection with a
  special built-in.
- An link:interact.html[interactive] shell does not execute the
  link:params.html#sv-prompt_command[+PROMPT_COMMAND+ variable] before
  printing a prompt.
  The values of the link:params.html#sv-ps1[+PS1+],
  link:params.html#sv-ps2[+PS2+], and link:params.html#sv-ps4[+PS4+] variables
  are parsed differently.
  Prompt variables with a +YASH_+ prefix (e.g.
  link:params.html#sv-yash_ps1[+YASH_PS1+]) are not used.
- In link:interact.html#mailcheck[mail checking], a notification message is
  printed if the file has been modified, regardless of whether the file is
  empty.

// vim: set filetype=asciidoc textwidth=78 expandtab:
