|GNU Bash Reference Manual|
by Chet Ramey and Brian Fox
Paperback (6"x9"), 180 pages
RRP £19.95 ($29.95)
"An essential resource .... the most detailed coverage available for all aspects of Bash" --- Linux User and Developer Magazine (Issue 37, Mar 2004) Get a printed copy>>>
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
The following list is what's changed when `POSIX mode' is in effect:
When a command in the hash table no longer exists, Bash will re-search
$PATHto find the new location. This is also available with ‘shopt -s checkhash’.
- The message printed by the job control code and builtins when a job exits with a non-zero status is `Done(status)'.
The message printed by the job control code and builtins when a job
is stopped is `Stopped(signame)', where signame is, for
bgbuiltin 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.
- Reserved words appearing in a context where reserved words are recognized do not undergo alias expansion.
PS2expansions of ‘!’ to the history number and ‘!!’ to ‘!’ are enabled, and parameter expansion is performed on the values of
PS2regardless of the setting of the
The POSIX startup files are executed (
$ENV) rather than the normal Bash files.
- Tilde expansion is only performed on assignments preceding a command name, rather than on all assignment statements on the line.
The default history file is ‘~/.sh_history’ (this is the
default value of
- The output of ‘kill -l’ prints all the signal names on a single line, separated by spaces, without the ‘SIG’ prefix.
killbuiltin does not accept signal names with a ‘SIG’ prefix.
Non-interactive shells exit if filename in
.filename is not found.
- Non-interactive shells exit if a syntax error in an arithmetic expansion results in an invalid expression.
- Redirection operators do not perform filename expansion on the word in the redirection unless the shell is interactive.
- Redirection operators do not perform word splitting on the word in the redirection.
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.
- POSIX special builtins are found before shell functions during command lookup.
- If a POSIX special builtin returns an error status, a non-interactive shell exits. The fatal errors are those listed in the POSIX standard, and include things like passing incorrect options, redirection errors, variable assignment errors for assignments preceding the command name, and so on.
CDPATHis set, the
cdbuiltin will not implicitly append the current directory to it. This means that
cdwill fail if no valid directory name can be constructed from any of the entries in
$CDPATH, even if the a directory with the same name as the name given as an argument to
cdexists in the current directory.
- A non-interactive shell exits with an error status if a variable assignment error occurs when no command name follows the assignment statements. A variable assignment error occurs, for example, when trying to assign a value to a readonly variable.
A non-interactive shell exits with an error status if the iteration
variable in a
forstatement or the selection variable in a
selectstatement is a readonly variable.
- Process substitution is not available.
- Assignment statements preceding POSIX special builtins persist in the shell environment after the builtin completes.
- Assignment statements preceding shell function calls persist in the shell environment after the function returns, as if a POSIX special builtin command had been executed.
readonlybuiltin commands display their output in the format required by POSIX.
trapbuiltin displays signal names without the leading
trapbuiltin doesn't check the first argument for a possible signal specification and revert the signal handling to the original disposition if it is, unless that argument consists solely of digits and is a valid signal number. If users want to reset the handler for a given signal to the original disposition, they should use ‘-’ as the first argument.
sourcebuiltins do not search the current directory for the filename argument if it is not found by searching
Subshells spawned to execute command substitutions inherit the value of
-eoption from the parent shell. When not in POSIX mode, Bash clears the
-eoption in such subshells.
- Alias expansion is always enabled, even in non-interactive shells.
aliasbuiltin displays alias definitions, it does not display them with a leading ‘alias ’ unless the
-poption is supplied.
setbuiltin is invoked without options, it does not display shell function names and definitions.
setbuiltin is invoked without options, it displays variable values without quotes, unless they contain shell metacharacters, even if the result contains nonprinting characters.
cdbuiltin is invoked in logical mode, and the pathname constructed from
$PWDand the directory name supplied as an argument does not refer to an existing directory,
cdwill fail instead of falling back to physical mode.
pwdbuiltin is supplied the
-Poption, it resets
$PWDto a pathname containing no symlinks.
pwdbuiltin verifies that the value it prints is the same as the current directory, even if it is not asked to check the file system with the
When listing the history, the
fcbuiltin does not include an indication of whether or not a history entry has been modified.
The default editor used by
commandbuiltins will not report a non-executable file as having been found, though the shell will attempt to execute such a file if it is the only so-named file found in
viediting mode will invoke the
vieditor directly when the ‘v’ command is run, instead of checking
xpg_echooption is enabled, Bash does not attempt to interpret any arguments to
echoas options. Each argument is displayed, after escape characters are converted.
There is other POSIX behavior that Bash does not implement by default even when in POSIX mode. Specifically:
$EDITORas a program to edit history entries if
FCEDITis unset, rather than defaulting directly to
As noted above, Bash requires the
xpg_echooption to be enabled for the
echobuiltin to be fully conformant.
Bash can be configured to be POSIX-conformant by default, by specifying
configure when building
(see section 10.8 Optional Features).
|ISBN 0954161777||GNU Bash Reference Manual||See the print edition|