diff options
author | Ron Yorston <rmy@pobox.com> | 2020-07-23 08:32:27 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-05 23:37:19 +0200 |
commit | a1b0d3856d9a0419cb74bf4c87525265871b5868 (patch) | |
tree | 1c3dface41c9c1f4d23a42819c9e6c2101e4f303 /shell/ash_test | |
parent | 8c1f8aa016faee3fa151d134c3544b2dd5bab832 (diff) | |
download | busybox-w32-a1b0d3856d9a0419cb74bf4c87525265871b5868.tar.gz busybox-w32-a1b0d3856d9a0419cb74bf4c87525265871b5868.tar.bz2 busybox-w32-a1b0d3856d9a0419cb74bf4c87525265871b5868.zip |
ash: add process substitution in bash-compatibility mode
Process substitution is a Korn shell feature that's also available
in bash and some other shells. This patch implements process
substitution in ash when ASH_BASH_COMPAT is enabled.
function old new delta
argstr 1386 1522 +136
strtodest - 52 +52
readtoken1 3346 3392 +46
.rodata 183206 183250 +44
unwindredir - 28 +28
cmdloop 365 372 +7
static.spclchars 10 12 +2
cmdputs 380 367 -13
exitreset 86 69 -17
evalcommand 1754 1737 -17
varvalue 675 634 -41
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/4 up/down: 315/-88) Total: 227 bytes
text data bss dec hex filename
953967 4219 1904 960090 ea65a busybox_old
954192 4219 1904 960315 ea73b busybox_unstripped
v2: Replace array of file descriptors with a linked list.
Include tests that were unaccountably omitted from v1.
v3: Update linked list code to the intended version.
v4: Change order of conditional code in cmdputs().
v5: Use existing popredir() mechanism to manage file descriptors.
v6: Rebase to latest version of BusyBox ash. Reduce code churn.
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test')
-rw-r--r-- | shell/ash_test/ash-psubst/bash_procsub.right | 9 | ||||
-rwxr-xr-x | shell/ash_test/ash-psubst/bash_procsub.tests | 33 |
2 files changed, 42 insertions, 0 deletions
diff --git a/shell/ash_test/ash-psubst/bash_procsub.right b/shell/ash_test/ash-psubst/bash_procsub.right new file mode 100644 index 000000000..aa16a96be --- /dev/null +++ b/shell/ash_test/ash-psubst/bash_procsub.right | |||
@@ -0,0 +1,9 @@ | |||
1 | hello 1 | ||
2 | hello 2 | ||
3 | hello 3 | ||
4 | <(echo "hello 0") | ||
5 | hello 4 | ||
6 | HI THERE | ||
7 | hello error | ||
8 | hello error | ||
9 | hello stderr | ||
diff --git a/shell/ash_test/ash-psubst/bash_procsub.tests b/shell/ash_test/ash-psubst/bash_procsub.tests new file mode 100755 index 000000000..63b836782 --- /dev/null +++ b/shell/ash_test/ash-psubst/bash_procsub.tests | |||
@@ -0,0 +1,33 @@ | |||
1 | # simplest case | ||
2 | cat <(echo "hello 1") | ||
3 | |||
4 | # can have more than one | ||
5 | cat <(echo "hello 2") <(echo "hello 3") | ||
6 | |||
7 | # doesn't work in quotes | ||
8 | echo "<(echo \"hello 0\")" | ||
9 | |||
10 | # process substitution can be nested inside command substitution | ||
11 | echo $(cat <(echo "hello 4")) | ||
12 | |||
13 | # example from http://wiki.bash-hackers.org/syntax/expansion/proc_subst | ||
14 | # process substitutions can be passed to a function as parameters or | ||
15 | # variables | ||
16 | f() { | ||
17 | cat "$1" >"$x" | ||
18 | } | ||
19 | x=>(tr '[:lower:]' '[:upper:]') f <(echo 'hi there') | ||
20 | |||
21 | # process substitution can be combined with redirection on exec | ||
22 | rm -f err | ||
23 | # save stderr | ||
24 | exec 4>&2 | ||
25 | # copy stderr to a file | ||
26 | exec 2> >(tee err) | ||
27 | echo "hello error" >&2 | ||
28 | sync | ||
29 | # restore stderr | ||
30 | exec 2>&4 | ||
31 | cat err | ||
32 | rm -f err | ||
33 | echo "hello stderr" >&2 | ||