Parameter expansion is not compatible with other shells
A Tool Box with tools written or managed by Jörg Schilling
Brought to you by:
schily
Using Schily Tools 2020-03-27 on Debian 10.3.
dash -c 'x="a*b"; y="a[*]b"; echo "${x#"$y"}"' # => a*b
bash -c 'x="a*b"; y="a[*]b"; echo "${x#"$y"}"' # => a*b
ksh -c 'x="a*b"; y="a[*]b"; echo "${x#"$y"}"' # => a*b
bosh -c 'x="a*b"; y="a[*]b"; echo "${x#"$y"}"' # => <empty>
pbosh -c 'x="a*b"; y="a[*]b"; echo "${x#"$y"}"' # => <empty>
dash -c 'a=; echo "${a:-"a b"}"' # => a b
bash -c 'a=; echo "${a:-"a b"}"' # => a b
ksh -c 'a=; echo "${a:-"a b"}"' # => a b
bosh -c 'a=; echo "${a:-"a b"}"' # bad substitution
pbosh -c 'a=; echo "${a:-"a b"}"' # bad substitution
The second example seems to be correct in bosh, as it shows the same results as ksh88 that is the base for the POSIX shell.
The fist example needs more checks.
Let me give an update:
Both commands address completely different problems.
The second command contains a space character and there was a plan to support this kind of problems 4 years ago. Background: the lexer normally sees two tokens and it needs to understand ${...} to include the unquoted space in a word. There should have been two changes in the lexer to support both ${...} and "${....}" but there was only one change for ${...}.
The first command seems to have been defined in a strange way by ksh. ksh seems to reset quoting after the '#' character.
The changes in word.c address the second command, the changes in macro.c address the first command.
Last edit: Jörg Schilling 2020-04-27
Thank you! It works perfectly!
My testing framework ShellSpec is depends on first example. Previously it used the fallback version using patterns matching, After applying this patch, It come to uses the posix version which is 20% speed faster!
Diff:
OK, then this is closed.