diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-17 23:51:00 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-17 23:51:00 +0200 |
| commit | 0e81e488fdec7d6b1d96439407b8a50737d35929 (patch) | |
| tree | c8b9887dd4d62d398a7cad8204f8e817abd1da04 | |
| parent | adc0e20892d55b8c762c6d259d3c87a100aec14d (diff) | |
| download | busybox-w32-0e81e488fdec7d6b1d96439407b8a50737d35929.tar.gz busybox-w32-0e81e488fdec7d6b1d96439407b8a50737d35929.tar.bz2 busybox-w32-0e81e488fdec7d6b1d96439407b8a50737d35929.zip | |
shell/README: describe special builtins
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | shell/README | 190 |
1 files changed, 82 insertions, 108 deletions
diff --git a/shell/README b/shell/README index 59efe499f..550c712d3 100644 --- a/shell/README +++ b/shell/README | |||
| @@ -1,108 +1,82 @@ | |||
| 1 | Various bits of what is known about busybox shells, in no particular order. | 1 | http://www.opengroup.org/onlinepubs/9699919799/ |
| 2 | 2 | Open Group Base Specifications Issue 7 | |
| 3 | 2008-02-14 | 3 | |
| 4 | ash: does not restore tty pgrp if killed by HUP. Symptom: Midnight Commander | 4 | |
| 5 | is backgrounded if you started ash under it, and then killed it with HUP. | 5 | http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html |
| 6 | 6 | Shell & Utilities | |
| 7 | 2007-11-23 | 7 | |
| 8 | hush: fixed bogus glob handling; fixed exec <"$1"; added test and echo builtins | 8 | It says that any of the standard utilities may be implemented |
| 9 | 9 | as a regular shell built-in. It gives a list of utilities which | |
| 10 | 2007-06-13 | 10 | are usually implemented that way (and some of them can only |
| 11 | hush: exec <"$1" doesn't do parameter subst | 11 | be implemented as built-ins, like "alias"): |
| 12 | 12 | ||
| 13 | 2007-05-24 | 13 | alias |
| 14 | hush: environment-related memory leak plugged, with net code size | 14 | bg |
| 15 | decrease. | 15 | cd |
| 16 | 16 | command | |
| 17 | 2007-05-24 | 17 | false |
| 18 | hush: '( echo ${name )' will show syntax error message, but prompt | 18 | fc |
| 19 | doesn't return (need to press <enter>). Pressing Ctrl-C, <enter>, | 19 | fg |
| 20 | '( echo ${name )' again, Ctrl-C segfaults. | 20 | getopts |
| 21 | 21 | jobs | |
| 22 | 2007-05-21 | 22 | kill |
| 23 | hush: environment cannot be handled by libc routines as they are leaky | 23 | newgrp |
| 24 | (by API design and thus unfixable): hush will leak memory in this script, | 24 | pwd |
| 25 | bash does not: | 25 | read |
| 26 | pid=$$ | 26 | true |
| 27 | while true; do | 27 | umask |
| 28 | unset t; | 28 | unalias |
| 29 | t=111111111111111111111111111111111111111111111111111111111111111111111111 | 29 | wait |
| 30 | export t | 30 | |
| 31 | ps -o vsz,pid,comm | grep " $pid " | 31 | |
| 32 | done | 32 | http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html |
| 33 | The fix is to not use setenv/putenv/unsetenv but manipulate env ourself. TODO. | 33 | Shell Command Language |
| 34 | hush: meanwhile, first three command subst bugs mentioned below are fixed. :) | 34 | |
| 35 | 35 | It says that shell must implement special built-ins. Special built-ins | |
| 36 | 2007-05-06 | 36 | differ from regular ones by the fact that variable assignments |
| 37 | hush: more bugs spotted. Comparison with bash: | 37 | done on special builtin is *PRESERVED*. That is, |
| 38 | bash-3.2# echo "TEST`date;echo;echo`BEST" | 38 | |
| 39 | TESTSun May 6 09:21:05 CEST 2007BEST [we dont strip eols] | 39 | VAR=VAL special_builtin; echo $VAR |
| 40 | bash-3.2# echo "TEST`echo '$(echo ZZ)'`BEST" | 40 | |
| 41 | TEST$(echo ZZ)BEST [we execute inner echo] | 41 | should print VAL. |
| 42 | bash-3.2# echo "TEST`echo "'"`BEST" | 42 | |
| 43 | TEST'BEST [we totally mess up this one] | 43 | (Another distinction is that an error in special built-in should |
| 44 | bash-3.2# echo `sleep 5` | 44 | abort the shell, but this is not such a critical difference, |
| 45 | [Ctrl-C should work, Ctrl-Z should do nothing][we totally mess up this one] | 45 | and moreover, at least bash's "set" does not follow this rule, |
| 46 | bash-3.2# if true; then | 46 | which is even codified in autoconf now...). |
| 47 | > [Ctrl-C] | 47 | |
| 48 | bash-3.2# [we re-issue "> "] | 48 | List of special builtins: |
| 49 | bash-3.2# if echo `sleep 5`; then | 49 | |
| 50 | > true; fi [we execute sleep before "> "] | 50 | . file |
| 51 | 51 | : [argument...] | |
| 52 | 2007-05-04 | 52 | break [n] |
| 53 | hush: made ctrl-Z/C work correctly for "while true; do true; done" | 53 | continue [n] |
| 54 | (namely, it backgrounds/interrupts entire "while") | 54 | eval [argument...] |
| 55 | 55 | exec [command [argument...]] | |
| 56 | 2007-05-03 | 56 | exit [n] |
| 57 | hush: new bug spotted: Ctrl-C on "while true; do true; done" doesn't | 57 | export name[=word]... |
| 58 | work right: | 58 | export -p |
| 59 | # while true; do true; done | 59 | readonly name[=word]... |
| 60 | [1] 0 true <-- pressing Ctrl-C several times... | 60 | readonly -p |
| 61 | [2] 0 true | 61 | return [n] |
| 62 | [3] 0 true | 62 | set [-abCefhmnuvx] [-o option] [argument...] |
| 63 | Segmentation fault | 63 | set [+abCefhmnuvx] [+o option] [argument...] |
| 64 | 64 | set -- [argument...] | |
| 65 | 2007-05-03 | 65 | set -o |
| 66 | hush: update on "sleep 1 | exit 3; echo $?" bug. | 66 | set +o |
| 67 | parse_stream_outer() repeatedly calls parse_stream(). | 67 | shift [n] |
| 68 | parse_stream() is now fixed to stop on ';' in this example, | 68 | times |
| 69 | fixing it (parse_stream_outer() will call parse_stream() 1st time, | 69 | trap n [condition...] |
| 70 | execute the parse tree, call parse_stream() 2nd time and execute the tree). | 70 | trap [action condition...] |
| 71 | But it's not the end of story. | 71 | unset [-fv] name... |
| 72 | In more complex situations we _must_ parse way farther before executing. | 72 | |
| 73 | Example #2: "{ sleep 1 | exit 3; echo $?; ...few_lines... } >file". | 73 | In practice, no one uses this obscure feature - none of these builtins |
| 74 | Because of redirection, we cannot execute 1st pipe before we parse it all. | 74 | gives any special reasons to play such dirty tricks. |
| 75 | We probably need to learn to store $var expressions in parse tree. | 75 | |
| 76 | Debug printing of parse tree would be nice too. | 76 | However. This section says that *function invocation* should act |
| 77 | 77 | similar to special built-in. That is, variable assignments | |
| 78 | 2007-04-28 | 78 | done on function invocation should be preserved after function invocation. |
| 79 | hush: Ctrl-C and Ctrl-Z for single NOFORK commands are working. | 79 | |
| 80 | Memory and other resource leaks (opendir) are not addressed | 80 | This is significant: it is not unthinkable to want to run a function |
| 81 | (testcase is "rm -i" interrupted by ctrl-c). | 81 | with some variables set to special values. But because of the above, |
| 82 | 82 | it does not work: variable will "leak" out of the function. | |
| 83 | 2007-04-21 | ||
| 84 | hush: "sleep 5 | sleep 6" + Ctrl-Z + fg seems to work. | ||
| 85 | "rm -i" + Ctrl-C, "sleep 5" + Ctrl-Z still doesn't work | ||
| 86 | for SH_STANDALONE case :( | ||
| 87 | |||
| 88 | 2007-04-21 | ||
| 89 | hush: fixed non-backgrounding of "sleep 1 &" and totally broken | ||
| 90 | "sleep 1 | sleep 2 &". Noticed a bug where successive jobs | ||
| 91 | get numbers 1,2,3 even when job #1 has exited before job# 2 is started. | ||
| 92 | (bash reuses #1 in this case) | ||
| 93 | |||
| 94 | 2007-04-21 | ||
| 95 | hush: "sleep 1 | exit 3; echo $?" prints 0 because $? is substituted | ||
| 96 | _before_ pipe gets executed!! run_list_real() already has "pipe;echo" | ||
| 97 | parsed and handed to it for execution, so it sees "pipe"; "echo 0". | ||
| 98 | |||
| 99 | 2007-04-21 | ||
| 100 | hush: removed setsid() and made job control sort-of-sometimes-work. | ||
| 101 | Ctrl-C in "rm -i" works now except for SH_STANDALONE case. | ||
| 102 | "sleep 1 | exit 3" + "echo $?" works, "sleep 1 | exit 3; echo $?" | ||
| 103 | shows exitcode 0 (should be 3). "sleep 1 | sleep 2 &" fails horribly. | ||
| 104 | |||
| 105 | 2007-04-14 | ||
| 106 | lash, hush: both do setsid() and as a result don't have ctty! | ||
| 107 | Ctrl-C doesn't work for any child (try rm -i), etc... | ||
| 108 | lash: bare ">file" doesn't create a file (hush works) | ||
