The following is reproducible with bosh and pbosh (tested schily-tools 2018-09-26, but I think it also happens with earlier versions).
I believe the following invocation should print the last char of $1 for any arbitrary $1:
posh -c 'in=$1; pre=${1%?}; out=${in#"$pre"}; printf [%s] "$out"' -- AB\"C
Expected result: [C]
Actual result: ["C]
For plain strings like ABC it does work.
I tried all 4 combinations of outer quotes ( out="${...}" ) and inner quotes ( out=${ .. "$pre" .. } ) and none worked. I believe at the very least either inner-only or inner+outer quotes should always work for arbitrary $1.
Tested on Ubuntu 18.04 LTS x64 with gcc 7.3.0, gnu make 4.1 .
All other shells which I tested perform as expected on any arbitrary $1 which I tried (including complex strings with single/double quotes, backslashe, shell reserved words, etc). I tested ksh93/dash/bash/mksh/yash/busybox-ash , and additionally also in posix-compliant mode with bash/yash/mksh.
Oops typo.. in
posh -cI meant bosh or pbosh.Please check the attached patch.
The problem here: It passes my unit test suite, but this may not be sufficient. So if you have more tests, please run them....
Confirmed that the patch fixes the test case and [p]bosh now print
[C]. Thanks.I'll let you know if I find other issues.
FWIW, I wrote and use this tool to compare output from different shells (the tool itself runs fine in [p]bosh), mostly to make sure constructs I use in scripts are as compatible as possible:
https://github.com/avih/shcmp
Last edit: Avi Halachmi 2018-10-09
The new version is available for download