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