From 95ebcf79ff6f8ad21ceacb7bac665fb86c078d84 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 3 Nov 2015 09:42:23 +0000 Subject: 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 Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-misc/func_bash1.right | 12 ++++++++++++ shell/ash_test/ash-misc/func_bash1.tests | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 shell/ash_test/ash-misc/func_bash1.right create mode 100755 shell/ash_test/ash-misc/func_bash1.tests (limited to 'shell/ash_test/ash-misc') 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 0000000..41bf882 --- /dev/null +++ b/shell/ash_test/ash-misc/func_bash1.right @@ -0,0 +1,12 @@ +1 +2 +3 +1 +2 +3 +1 +2 +3 +1 +2 +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 0000000..2cc0970 --- /dev/null +++ b/shell/ash_test/ash-misc/func_bash1.tests @@ -0,0 +1,28 @@ +function f() { echo $1; } +f 1 + +function f() ( echo $1; ) +f 2 + +function f() ( echo $1 ) +f 3 + +function f() for i in 1 2 3; do + echo $i +done +f + +function f { echo $1; } +f 1 + +# the next two don't work +#function f ( echo $1; ) +f 2 + +#function f ( echo $1 ) +f 3 + +function f for i in 1 2 3; do + echo $i +done +f -- cgit v1.1