Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 1 | This document details the incompatibilities between this version of bash, |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 2 | bash-4.0, and the previous widely-available versions, bash-1.14 (which is |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 3 | still the `standard' version for a few Linux distributions) and bash-2.x. |
| 4 | These were discovered by users of bash-2.x and 3.x, so this list is not |
| 5 | comprehensive. Some of these incompatibilities occur between the current |
| 6 | version and versions 2.0 and above. (The differences between bash-1.14 and |
| 7 | bash-2.0 were significant.) |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 8 | |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 9 | 1. Bash uses a new quoting syntax, $"...", to do locale-specific |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 10 | string translation. Users who have relied on the (undocumented) |
| 11 | behavior of bash-1.14 will have to change their scripts. For |
| 12 | instance, if you are doing something like this to get the value of |
| 13 | a variable whose name is the value of a second variable: |
| 14 | |
| 15 | eval var2=$"$var1" |
| 16 | |
| 17 | you will have to change to a different syntax. |
| 18 | |
| 19 | This capability is directly supported by bash-2.0: |
| 20 | |
| 21 | var2=${!var1} |
| 22 | |
| 23 | This alternate syntax will work portably between bash-1.14 and bash-2.0: |
| 24 | |
| 25 | eval var2=\$${var1} |
| 26 | |
| 27 | 2. One of the bugs fixed in the YACC grammar tightens up the rules |
| 28 | concerning group commands ( {...} ). The `list' that composes the |
| 29 | body of the group command must be terminated by a newline or |
| 30 | semicolon. That's because the braces are reserved words, and are |
| 31 | recognized as such only when a reserved word is legal. This means |
| 32 | that while bash-1.14 accepted shell function definitions like this: |
| 33 | |
| 34 | foo() { : } |
| 35 | |
| 36 | bash-2.0 requires this: |
| 37 | |
| 38 | foo() { :; } |
| 39 | |
| 40 | This is also an issue for commands like this: |
| 41 | |
| 42 | mkdir dir || { echo 'could not mkdir' ; exit 1; } |
| 43 | |
| 44 | The syntax required by bash-2.0 is also accepted by bash-1.14. |
| 45 | |
| 46 | 3. The options to `bind' have changed to make them more consistent with |
| 47 | the rest of the bash builtins. If you are using `bind -d' to list |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 48 | the readline key bindings in a form that can be re-read, use `bind -p' |
| 49 | instead. If you were using `bind -v' to list the key bindings, use |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 50 | `bind -P' instead. |
| 51 | |
| 52 | 4. The `long' invocation options must now be prefixed by `--' instead |
| 53 | of `-'. (The old form is still accepted, for the time being.) |
| 54 | |
| 55 | 5. There was a bug in the version of readline distributed with bash-1.14 |
| 56 | that caused it to write badly-formatted key bindings when using |
| 57 | `bind -d'. The only key sequences that were affected are C-\ (which |
| 58 | should appear as \C-\\ in a key binding) and C-" (which should appear |
| 59 | as \C-\"). If these key sequences appear in your inputrc, as, for |
| 60 | example, |
| 61 | |
| 62 | "\C-\": self-insert |
| 63 | |
| 64 | they will need to be changed to something like the following: |
| 65 | |
| 66 | "\C-\\": self-insert |
| 67 | |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 68 | 6. A number of people complained about having to use ESC to terminate an |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 69 | incremental search, and asked for an alternate mechanism. Bash-2.03 |
| 70 | uses the value of the settable readline variable `isearch-terminators' |
| 71 | to decide which characters should terminate an incremental search. If |
| 72 | that variable has not been set, ESC and Control-J will terminate a |
| 73 | search. |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 74 | |
| 75 | 7. Some variables have been removed: MAIL_WARNING, notify, history_control, |
| 76 | command_oriented_history, glob_dot_filenames, allow_null_glob_expansion, |
| 77 | nolinks, hostname_completion_file, noclobber, no_exit_on_failed_exec, and |
| 78 | cdable_vars. Most of them are now implemented with the new `shopt' |
Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 79 | builtin; others were already implemented by `set'. Here is a list of |
| 80 | correspondences: |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 81 | |
Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 82 | MAIL_WARNING shopt mailwarn |
| 83 | notify set -o notify |
| 84 | history_control HISTCONTROL |
| 85 | command_oriented_history shopt cmdhist |
| 86 | glob_dot_filenames shopt dotglob |
| 87 | allow_null_glob_expansion shopt nullglob |
| 88 | nolinks set -o physical |
| 89 | hostname_completion_file HOSTFILE |
| 90 | noclobber set -o noclobber |
| 91 | no_exit_on_failed_exec shopt execfail |
| 92 | cdable_vars shopt cdable_vars |
| 93 | |
| 94 | 8. `ulimit' now sets both hard and soft limits and reports the soft limit |
| 95 | by default (when neither -H nor -S is specified). This is compatible |
| 96 | with versions of sh and ksh that implement `ulimit'. The bash-1.14 |
| 97 | behavior of, for example, |
| 98 | |
| 99 | ulimit -c 0 |
| 100 | |
| 101 | can be obtained with |
| 102 | |
| 103 | ulimit -S -c 0 |
| 104 | |
| 105 | It may be useful to define an alias: |
| 106 | |
| 107 | alias ulimit="ulimit -S" |
| 108 | |
Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 109 | 9. Bash-2.01 uses a new quoting syntax, $'...' to do ANSI-C string |
| 110 | translation. Backslash-escaped characters in ... are expanded and |
| 111 | replaced as specified by the ANSI C standard. |
| 112 | |
| 113 | 10. The sourcing of startup files has changed somewhat. This is explained |
| 114 | more completely in the INVOCATION section of the manual page. |
| 115 | |
| 116 | A non-interactive shell not named `sh' and not in posix mode reads |
| 117 | and executes commands from the file named by $BASH_ENV. A |
| 118 | non-interactive shell started by `su' and not in posix mode will read |
| 119 | startup files. No other non-interactive shells read any startup files. |
| 120 | |
| 121 | An interactive shell started in posix mode reads and executes commands |
| 122 | from the file named by $ENV. |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 123 | |
| 124 | 11. The <> redirection operator was changed to conform to the POSIX.2 spec. |
| 125 | In the absence of any file descriptor specification preceding the `<>', |
| 126 | file descriptor 0 is used. In bash-1.14, this was the behavior only |
| 127 | when in POSIX mode. The bash-1.14 behavior may be obtained with |
| 128 | |
| 129 | <>filename 1>&0 |
Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 130 | |
| 131 | 12. The `alias' builtin now checks for invalid options and takes a `-p' |
| 132 | option to display output in POSIX mode. If you have old aliases beginning |
| 133 | with `-' or `+', you will have to add the `--' to the alias command |
| 134 | that declares them: |
| 135 | |
| 136 | alias -x='chmod a-x' --> alias -- -x='chmod a-x' |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 137 | |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 138 | 13. The behavior of range specificiers within bracket matching expressions |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 139 | in the pattern matcher (e.g., [A-Z]) depends on the current locale, |
| 140 | specifically the value of the LC_COLLATE environment variable. Setting |
| 141 | this variable to C or POSIX will result in the traditional ASCII behavior |
| 142 | for range comparisons. If the locale is set to something else, e.g., |
| 143 | en_US (specified by the LANG or LC_ALL variables), collation order is |
| 144 | locale-dependent. For example, the en_US locale sorts the upper and |
| 145 | lower case letters like this: |
| 146 | |
| 147 | AaBb...Zz |
| 148 | |
| 149 | so a range specification like [A-Z] will match every letter except `z'. |
Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 150 | Other locales collate like |
| 151 | |
| 152 | aAbBcC...zZ |
| 153 | |
| 154 | which means that [A-Z] matches every letter except `a'. |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 155 | |
| 156 | The portable way to specify upper case letters is [:upper:] instead of |
| 157 | A-Z; lower case may be specified as [:lower:] instead of a-z. |
| 158 | |
| 159 | Look at the manual pages for setlocale(3), strcoll(3), and, if it is |
| 160 | present, locale(1). |
| 161 | |
| 162 | You can find your current locale information by running locale(1): |
| 163 | |
| 164 | caleb.ins.cwru.edu(2)$ locale |
| 165 | LANG=en_US |
| 166 | LC_CTYPE="en_US" |
| 167 | LC_NUMERIC="en_US" |
| 168 | LC_TIME="en_US" |
| 169 | LC_COLLATE="en_US" |
| 170 | LC_MONETARY="en_US" |
| 171 | LC_MESSAGES="en_US" |
| 172 | LC_ALL=en_US |
| 173 | |
| 174 | My advice is to put |
| 175 | |
| 176 | export LC_COLLATE=C |
| 177 | |
| 178 | into /etc/profile and inspect any shell scripts run from cron for |
| 179 | constructs like [A-Z]. This will prevent things like |
| 180 | |
| 181 | rm [A-Z]* |
| 182 | |
| 183 | from removing every file in the current directory except those beginning |
| 184 | with `z' and still allow individual users to change the collation order. |
| 185 | Users may put the above command into their own profiles as well, of course. |
| 186 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 187 | 14. Bash versions up to 1.14.7 included an undocumented `-l' operator to |
| 188 | the `test/[' builtin. It was a unary operator that expanded to the |
| 189 | length of its string argument. This let you do things like |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 190 | |
| 191 | test -l $variable -lt 20 |
| 192 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 193 | for example. |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 194 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 195 | This was included for backwards compatibility with old versions of the |
| 196 | Bourne shell, which did not provide an easy way to obtain the length of |
| 197 | the value of a shell variable. |
Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 198 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 199 | This operator is not part of the POSIX standard, because one can (and |
| 200 | should) use ${#variable} to get the length of a variable's value. |
| 201 | Bash-2.x does not support it. |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 202 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 203 | 15. Bash no longer auto-exports the HOME, PATH, SHELL, TERM, HOSTNAME, |
| 204 | HOSTTYPE, MACHTYPE, or OSTYPE variables. If they appear in the initial |
| 205 | environment, the export attribute will be set, but if bash provides a |
| 206 | default value, they will remain local to the current shell. |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 207 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 208 | 16. Bash no longer initializes the FUNCNAME, GROUPS, or DIRSTACK variables |
| 209 | to have special behavior if they appear in the initial environment. |
Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 210 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 211 | 17. Bash no longer removes the export attribute from the SSH_CLIENT or |
| 212 | SSH2_CLIENT variables, and no longer attempts to discover whether or |
| 213 | not it has been invoked by sshd in order to run the startup files. |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 214 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 215 | 18. Bash no longer requires that the body of a function be a group command; |
| 216 | any compound command is accepted. |
Jari Aalto | 95732b4 | 2005-12-07 14:08:12 +0000 | [diff] [blame] | 217 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 218 | 19. As of bash-3.0, the pattern substitution operators no longer perform |
| 219 | quote removal on the pattern before attempting the match. This is the |
| 220 | way the pattern removal functions behave, and is more consistent. |
Jari Aalto | 95732b4 | 2005-12-07 14:08:12 +0000 | [diff] [blame] | 221 | |
Jari Aalto | 0628567 | 2006-10-10 14:15:34 +0000 | [diff] [blame] | 222 | 20. After bash-3.0 was released, I reimplemented tilde expansion, incorporating |
| 223 | it into the mainline word expansion code. This fixes the bug that caused |
| 224 | the results of tilde expansion to be re-expanded. There is one |
| 225 | incompatibility: a ${paramOPword} expansion within double quotes will not |
| 226 | perform tilde expansion on WORD. This is consistent with the other |
| 227 | expansions, and what POSIX specifies. |
| 228 | |
| 229 | 21. A number of variables have the integer attribute by default, so the += |
| 230 | assignment operator returns expected results: RANDOM, LINENO, MAILCHECK, |
| 231 | HISTCMD, OPTIND. |
| 232 | |
| 233 | 22. Bash-3.x is much stricter about $LINENO correctly reflecting the line |
| 234 | number in a script; assignments to LINENO have little effect. |
| 235 | |
| 236 | 23. By default, readline binds the terminal special characters to their |
| 237 | readline equivalents. As of bash-3.1/readline-5.1, this is optional and |
| 238 | controlled by the bind-tty-special-chars readline variable. |
| 239 | |
| 240 | 24. The \W prompt string expansion abbreviates $HOME as `~'. The previous |
| 241 | behavior is available with ${PWD##/*/}. |
| 242 | |
| 243 | 25. The arithmetic exponentiation operator is right-associative as of bash-3.1. |
| 244 | |
| 245 | 26. The rules concerning valid alias names are stricter, as per POSIX.2. |
| 246 | |
| 247 | 27. The Readline key binding functions now obey the convert-meta setting active |
| 248 | when the binding takes place, as the dispatch code does when characters |
| 249 | are read and processed. |
| 250 | |
| 251 | 28. The historical behavior of `trap' reverting signal disposition to the |
| 252 | original handling in the absence of a valid first argument is implemented |
| 253 | only if the first argument is a valid signal number. |
| 254 | |
| 255 | 29. In versions of bash after 3.1, the ${parameter//pattern/replacement} |
| 256 | expansion does not interpret `%' or `#' specially. Those anchors don't |
| 257 | have any real meaning when replacing every match. |
| 258 | |
| 259 | 30. Beginning with bash-3.1, the combination of posix mode and enabling the |
| 260 | `xpg_echo' option causes echo to ignore all options, not looking for `-n' |
| 261 | |
| 262 | 31. Beginning with bash-3.2, bash follows the Bourne-shell-style (and POSIX- |
| 263 | style) rules for parsing the contents of old-style backquoted command |
| 264 | substitutions. Previous versions of bash attempted to recursively parse |
| 265 | embedded quoted strings and shell constructs; bash-3.2 uses strict POSIX |
| 266 | rules to find the closing backquote and simply passes the contents of the |
| 267 | command substitution to a subshell for parsing and execution. |
| 268 | |
| 269 | 32. Beginning with bash-3.2, bash uses access(2) when executing primaries for |
| 270 | the test builtin and the [[ compound command, rather than looking at the |
| 271 | file permission bits obtained with stat(2). This obeys restrictions of |
| 272 | the file system (e.g., read-only or noexec mounts) not available via stat. |
| 273 | |
Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 274 | 33. Bash-3.2 adopts the convention used by other string and pattern matching |
| 275 | operators for the `[[' compound command, and matches any quoted portion |
| 276 | of the right-hand-side argument to the =~ operator as a string rather |
| 277 | than a regular expression. |
| 278 | |
| 279 | 34. Bash-4.0 allows the behavior in the previous item to be modified using |
| 280 | the notion of a shell `compatibility level'. |
| 281 | |
| 282 | 35. Bash-3.2 (patched) and Bash-4.0 fix a bug that leaves the shell in an |
| 283 | inconsistent internal state following an assignment error. One of the |
| 284 | changes means that compound commands or { ... } grouping commands are |
| 285 | aborted under some circumstances in which they previously were not. |
| 286 | This is what Posix specifies. |
| 287 | |
| 288 | 36. Bash-4.0 now allows process substitution constructs to pass unchanged |
| 289 | through brace expansion, so any expansion of the contents will have to be |
| 290 | separately specified, and each process subsitution will have to be |
| 291 | separately entered. |
| 292 | |
| 293 | 37. Bash-4.0 now allows SIGCHLD to interrupt the wait builtin, as Posix |
| 294 | specifies, so the SIGCHLD trap is no longer always invoked once per |
| 295 | exiting child if you are using `wait' to wait for all children. |
| 296 | |
| 297 | 38. Since bash-4.0 now follows Posix rules for finding the closing delimiter |
| 298 | of a $() command substitution, it will not behave as previous versions |
| 299 | did, but will catch more syntax and parsing errors before spawning a |
| 300 | subshell to evaluate the command substitution. |
| 301 | |
| 302 | 39. The programmable completion code uses the same set of delimiting characters |
| 303 | as readline when breaking the command line into words, rather than the |
| 304 | set of shell metacharacters, so programmable completion and readline |
| 305 | should be more consistent. |
| 306 | |
| 307 | 40. When the read builtin times out, it attempts to assign any input read to |
| 308 | specified variables, which also causes variables to be set to the empty |
| 309 | string if there is not enough input. Previous versions discarded the |
| 310 | characters read. |
| 311 | |
| 312 | 41. Beginning with bash-4.0, when one of the commands in a pipeline is killed |
| 313 | by a SIGINT while executing a command list, the shell acts as if it |
| 314 | received the interrupt. |
Jari Aalto | 17345e5 | 2009-02-19 22:21:29 +0000 | [diff] [blame] | 315 | |
| 316 | 42. Bash-4.0 changes the handling of the set -e option so that the shell exits |
| 317 | if a pipeline fails (and not just if the last command in the failing |
| 318 | pipeline is a simple command). This is not as Posix specifies. There is |
| 319 | work underway to update this portion of the standard; the bash-4.0 |
| 320 | behavior attempts to capture the consensus at the time of release. |