diff options
author | Ron Yorston <rmy@pobox.com> | 2015-11-03 09:42:23 +0000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-11-04 19:30:24 +0100 |
commit | 95ebcf79ff6f8ad21ceacb7bac665fb86c078d84 (patch) | |
tree | 0097c5c035161420a962dc70d8b1240092063355 /shell/ash_test/ash-misc | |
parent | bc9bee01f35d6c716c087e82dae5f439de90914b (diff) | |
download | busybox-w32-95ebcf79ff6f8ad21ceacb7bac665fb86c078d84.tar.gz busybox-w32-95ebcf79ff6f8ad21ceacb7bac665fb86c078d84.tar.bz2 busybox-w32-95ebcf79ff6f8ad21ceacb7bac665fb86c078d84.zip |
ash: add support for bash 'function' keyword
Where the POSIX shell allows functions to be defined as:
name () compound-command [ redirections ]
bash adds the alternative syntax:
function name [()] compound-command [ redirections ]
Implement this in ash's bash compatibility mode. Most compound
commands work (for/while/until/if/case/[[]]/{}); one exception is:
function f (echo "no way!")
The other two variants work:
f() (echo "ok")
function f() (echo "also ok")
function old new delta
parse_command 1555 1744 +189
tokname_array 232 240 +8
.rodata 155612 155566 -46
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 197/-46) Total: 151 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test/ash-misc')
-rw-r--r-- | shell/ash_test/ash-misc/func_bash1.right | 12 | ||||
-rwxr-xr-x | shell/ash_test/ash-misc/func_bash1.tests | 28 |
2 files changed, 40 insertions, 0 deletions
diff --git a/shell/ash_test/ash-misc/func_bash1.right b/shell/ash_test/ash-misc/func_bash1.right new file mode 100644 index 000000000..41bf8828c --- /dev/null +++ b/shell/ash_test/ash-misc/func_bash1.right | |||
@@ -0,0 +1,12 @@ | |||
1 | 1 | ||
2 | 2 | ||
3 | 3 | ||
4 | 1 | ||
5 | 2 | ||
6 | 3 | ||
7 | 1 | ||
8 | 2 | ||
9 | 3 | ||
10 | 1 | ||
11 | 2 | ||
12 | 3 | ||
diff --git a/shell/ash_test/ash-misc/func_bash1.tests b/shell/ash_test/ash-misc/func_bash1.tests new file mode 100755 index 000000000..2cc0970e8 --- /dev/null +++ b/shell/ash_test/ash-misc/func_bash1.tests | |||
@@ -0,0 +1,28 @@ | |||
1 | function f() { echo $1; } | ||
2 | f 1 | ||
3 | |||
4 | function f() ( echo $1; ) | ||
5 | f 2 | ||
6 | |||
7 | function f() ( echo $1 ) | ||
8 | f 3 | ||
9 | |||
10 | function f() for i in 1 2 3; do | ||
11 | echo $i | ||
12 | done | ||
13 | f | ||
14 | |||
15 | function f { echo $1; } | ||
16 | f 1 | ||
17 | |||
18 | # the next two don't work | ||
19 | #function f ( echo $1; ) | ||
20 | f 2 | ||
21 | |||
22 | #function f ( echo $1 ) | ||
23 | f 3 | ||
24 | |||
25 | function f for i in 1 2 3; do | ||
26 | echo $i | ||
27 | done | ||
28 | f | ||