diff options
author | Johnothan King <johnothanking@protonmail.com> | 2024-01-22 11:19:54 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 20:19:54 +0100 |
commit | add31baedaf03b92dbd41427860c61c639ef705c (patch) | |
tree | 61cb9148281adad01c27f9d0178d1a15b69696fb /runtime/syntax/testdir/input | |
parent | 7c71db3a58f658b4329b82ab603efa928d17bdbc (diff) |
runtime(sh): Add handling for ksh93 shared-state comsubs and mksh valsubs (#13884)
This commit adds support for ksh93 shared-state command
substitutions (syntax: ${ command; }) and mksh's value
substitutions (syntax: ${|command;}) in the sh syntax script.
Also add a syntax test for ksh subshares with dumps included
to make sure it doesn't regress.
fixes: #9514
Signed-off-by: Johnothan King <johnothanking@protonmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'runtime/syntax/testdir/input')
-rw-r--r-- | runtime/syntax/testdir/input/sh_10.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/runtime/syntax/testdir/input/sh_10.sh b/runtime/syntax/testdir/input/sh_10.sh new file mode 100644 index 0000000000..be463c3da0 --- /dev/null +++ b/runtime/syntax/testdir/input/sh_10.sh @@ -0,0 +1,49 @@ +#!/bin/ksh + +# This script is a test file for ksh93 shared-state +# command substitutions (subshares) and mksh value +# substitutions (valsubs). + +# ====== +# Below is subshare syntax supported by both ksh93 and mksh. +print ${ echo one } +print ${ echo two +} +print ${ +echo three } +print ${ echo 'four'; } +print ${ echo 'five' ;} +print ${ echo 'six' +} +print ${ echo 'seven' } +echo ${ print 'eight' } +typeset nine=${ pwd; } + +# ====== +# Value substitutions of the form ${|command} are only +# supported by mksh, not ksh93. +if ! command eval '((.sh.version >= 20070703))' 2>/dev/null; then + valsubfunc() { + REPLY=$1 + } + echo ${|valsubfunc ten} + print "${|valsubfunc eleven;}" + printf '%s' "${|valsubfunc twelve }" + unlucky=${|valsubfunc thirteen +} + typeset notafloat=${|valsubfunc notanumber } + print $unlucky $notanumber + ${|echo foo} + ${|echo bar +} +fi + +# ====== +# Shared-state command substitutions using the syntax ${<file;} +# are only supported by ksh93, not mksh. +echo ${ + printf %s str +} > /tmp/strfile +echo ${</tmp/strfile;} + +exit 0 |