6.11 Bash POSIX Mode
Starting Bash with the --posix command-line option or executing ‘set -o posix’ while
Bash is running will cause Bash to conform more closely to the posix standard by changing the behavior to match that specified by posix in areas where the Bash default differs.
When invoked as sh, Bash enters posix mode after reading the startup files.
The following list is what’s changed when ‘posix mode’ is in effect:
1. When a command in the hash table no longer exists, Bash will re-search $PATH to find the new location. This is also available with ‘shopt -s checkhash’.
2. The message printed by the job control code and builtins when a job exits with a non-zero status is ‘Done(status)’.
3. The message printed by the job control code and builtins when a job is stopped is
‘Stopped(signame)’, where signame is, for example, SIGTSTP.
4. The bg builtin uses the required format to describe each job placed in the background, which does not include an indication of whether the job is the current or previous job.
5. Reserved words appearing in a context where reserved words are recognized do not undergo alias expansion.
6. The posix PS1 and PS2 expansions of ‘!’ to the history number and ‘!!’ to ‘!’ are enabled, and parameter expansion is performed on the values of PS1 and PS2 regardless of the setting of the promptvars option.
7. The posix startup files are executed ($ENV) rather than the normal Bash files.
8. Tilde expansion is only performed on assignments preceding a command name, rather than on all assignment statements on the line.
9. The command builtin does not prevent builtins that take assignment statements as ar- guments from expanding them as assignment statements; when not in posix mode, assignment builtins lose their assignment statement expansion properties when pre- ceded by command.
10. The default history file is ~/.sh_history (this is the default value of $HISTFILE).
11. The output of ‘kill -l’ prints all the signal names on a single line, separated by spaces, without the ‘SIG’ prefix.
12. The kill builtin does not accept signal names with a ‘SIG’ prefix.
13. Non-interactive shells exit if filename in . filename is not found.
14. Non-interactive shells exit if a syntax error in an arithmetic expansion results in an invalid expression.
15. Non-interactive shells exit if there is a syntax error in a script read with the . or source builtins, or in a string processed by the eval builtin.
16. Redirection operators do not perform filename expansion on the word in the redirection unless the shell is interactive.
17. Redirection operators do not perform word splitting on the word in the redirection.
18. Function names must be valid shell names. That is, they may not contain characters other than letters, digits, and underscores, and may not start with a digit. Declaring a function with an invalid name causes a fatal syntax error in non-interactive shells.
19. Function names may not be the same as one of the posix special builtins.