📄 compat
字号:
This was included for backwards compatibility with old versions of the Bourne shell, which did not provide an easy way to obtain the length of the value of a shell variable. This operator is not part of the POSIX standard, because one can (and should) use ${#variable} to get the length of a variable's value. Bash-2.x does not support it.15. Bash no longer auto-exports the HOME, PATH, SHELL, TERM, HOSTNAME, HOSTTYPE, MACHTYPE, or OSTYPE variables. If they appear in the initial environment, the export attribute will be set, but if bash provides a default value, they will remain local to the current shell.16. Bash no longer initializes the FUNCNAME, GROUPS, or DIRSTACK variables to have special behavior if they appear in the initial environment.17. Bash no longer removes the export attribute from the SSH_CLIENT or SSH2_CLIENT variables, and no longer attempts to discover whether or not it has been invoked by sshd in order to run the startup files.18. Bash no longer requires that the body of a function be a group command; any compound command is accepted.19. As of bash-3.0, the pattern substitution operators no longer perform quote removal on the pattern before attempting the match. This is the way the pattern removal functions behave, and is more consistent.20. After bash-3.0 was released, I reimplemented tilde expansion, incorporating it into the mainline word expansion code. This fixes the bug that caused the results of tilde expansion to be re-expanded. There is one incompatibility: a ${paramOPword} expansion within double quotes will not perform tilde expansion on WORD. This is consistent with the other expansions, and what POSIX specifies.21. A number of variables have the integer attribute by default, so the += assignment operator returns expected results: RANDOM, LINENO, MAILCHECK, HISTCMD, OPTIND.22. Bash-3.x is much stricter about $LINENO correctly reflecting the line number in a script; assignments to LINENO have little effect.23. By default, readline binds the terminal special characters to their readline equivalents. As of bash-3.1/readline-5.1, this is optional and controlled by the bind-tty-special-chars readline variable.24. The \W prompt string expansion abbreviates $HOME as `~'. The previous behavior is available with ${PWD##/*/}.25. The arithmetic exponentiation operator is right-associative as of bash-3.1.26. The rules concerning valid alias names are stricter, as per POSIX.2.27. The Readline key binding functions now obey the convert-meta setting active when the binding takes place, as the dispatch code does when characters are read and processed.28. The historical behavior of `trap' reverting signal disposition to the original handling in the absence of a valid first argument is implemented only if the first argument is a valid signal number.29. In versions of bash after 3.1, the ${parameter//pattern/replacement} expansion does not interpret `%' or `#' specially. Those anchors don't have any real meaning when replacing every match.30. Beginning with bash-3.1, the combination of posix mode and enabling the `xpg_echo' option causes echo to ignore all options, not looking for `-n'31. Beginning with bash-3.2, bash follows the Bourne-shell-style (and POSIX- style) rules for parsing the contents of old-style backquoted command substitutions. Previous versions of bash attempted to recursively parse embedded quoted strings and shell constructs; bash-3.2 uses strict POSIX rules to find the closing backquote and simply passes the contents of the command substitution to a subshell for parsing and execution.32. Beginning with bash-3.2, bash uses access(2) when executing primaries for the test builtin and the [[ compound command, rather than looking at the file permission bits obtained with stat(2). This obeys restrictions of the file system (e.g., read-only or noexec mounts) not available via stat.33. Bash-3.2 adopts the convention used by other string and pattern matching operators for the `[[' compound command, and matches any quoted portion of the right-hand-side argument to the =~ operator as a string rather than a regular expression.34. Bash-4.0 allows the behavior in the previous item to be modified using the notion of a shell `compatibility level'. If the compat31 shopt option is set, quoting the pattern has no special effect.35. Bash-3.2 (patched) and Bash-4.0 fix a bug that leaves the shell in an inconsistent internal state following an assignment error. One of the changes means that compound commands or { ... } grouping commands are aborted under some circumstances in which they previously were not. This is what Posix specifies.36. Bash-4.0 now allows process substitution constructs to pass unchanged through brace expansion, so any expansion of the contents will have to be separately specified, and each process subsitution will have to be separately entered.37. Bash-4.0 now allows SIGCHLD to interrupt the wait builtin, as Posix specifies, so the SIGCHLD trap is no longer always invoked once per exiting child if you are using `wait' to wait for all children. As of bash-4.2, this is the status quo only when in posix mode.38. Since bash-4.0 now follows Posix rules for finding the closing delimiter of a $() command substitution, it will not behave as previous versions did, but will catch more syntax and parsing errors before spawning a subshell to evaluate the command substitution.39. The programmable completion code uses the same set of delimiting characters as readline when breaking the command line into words, rather than the set of shell metacharacters, so programmable completion and readline should be more consistent.40. When the read builtin times out, it attempts to assign any input read to specified variables, which also causes variables to be set to the empty string if there is not enough input. Previous versions discarded the characters read.41. Beginning with bash-4.0, when one of the commands in a pipeline is killed by a SIGINT while executing a command list, the shell acts as if it received the interrupt. This can be disabled by setting the compat31 or compat32 shell options.42. Bash-4.0 changes the handling of the set -e option so that the shell exits if a pipeline fails (and not just if the last command in the failing pipeline is a simple command). This is not as Posix specifies. There is work underway to update this portion of the standard; the bash-4.0 behavior attempts to capture the consensus at the time of release.43. Bash-4.0 fixes a Posix mode bug that caused the . (source) builtin to search the current directory for its filename argument, even if "." is not in $PATH. Posix says that the shell shouldn't look in $PWD in this case.44. Bash-4.1 uses the current locale when comparing strings using the < and > operators to the `[[' command. This can be reverted to the previous behavior (ASCII collating and strcmp(3)) by setting one of the `compatNN' shopt options, where NN is less than 41.45. Command substitutions now remove the caller's trap strings when trap is run to set a new trap in the subshell. Previous to bash-4.2, the old trap strings persisted even though the actual signal handlers were reset.46. When in Posix mode, a single quote is not treated specially in a double-quoted ${...} expansion, unless the expansion operator is # or % or the new `//', `^', or `,' expansions. In particular, it does not define a new quoting context. This is from Posix interpretation 221.47. Posix mode shells no longer exit if a variable assignment error occurs with an assignment preceding a command that is not a special builtin.Shell Compatibility Level=========================Bash-4.0 introduced the concept of a `shell compatibility level', specifiedas a set of options to the shopt builtin (compat31, compat32, compat40, andcompat41 at this writing). There is only one current compatibility level --each option is mutually exclusive. This list does not mention behaviorthat is standard for a particular version (e.g., setting compat32 means thatquoting the rhs of the regexp matching operator quotes special regexpcharacters in the word, which is default behavior in bash-3.2 and above).compat31 set - the < and > operators to the [[ command do not consider the current locale when comparing strings; they use ASCII ordering - quoting the rhs of the regexp matching operator (=~) has no special effectcompat32 set - the < and > operators to the [[ command do not consider the current locale when comparing strings; they use ASCII orderingcompat40 set - the < and > operators to the [[ command do not consider the current locale when comparing strings; they use ASCII ordering - interrupting a command list such as "a ; b ; c" causes the execution of the entire list to be aborted (in versions before bash-4.0, interrupting one command in a list caused the next to be executed)compat41 set - interrupting a command list such as "a ; b ; c" causes the execution of the entire list to be aborted (in versions before bash-4.0, interrupting one command in a list caused the next to be executed) - when in posix mode, single quotes in the `word' portion of a double-quoted parameter expansion define a new quoting context and are treated specially-------------------------------------------------------------------------------Copying and distribution of this file, with or without modification,are permitted in any medium without royalty provided the copyrightnotice and this notice are preserved. This file is offered as-is,without any warranty.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -