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