11 Ocak 2021 Pazartesi tarihinde Chet Ramey <chet.ra...@case.edu> yazdı:
> On 1/11/21 11:33 AM, Oğuz wrote: > >> >> >> 11 Ocak 2021 Pazartesi tarihinde Chet Ramey <chet.ra...@case.edu <mailto: >> chet.ra...@case.edu>> yazdı: >> >> What semantics would you choose to change? >> >> >> If you are reluctant to change semantics, how about a new parameter >> transformation to quote values using `sh_single_quote'? >> > > Why, when @Q already exists? > Because it doesn't always work. bash-5.1$ x=$'\n\'' y='x],b[$(uname >&2)0' bash-5.1$ declare -A assoc=($x 23 $y 42) bash-5.1$ bash-5.1$ (( assoc[${x@Q}]++ )) bash: ((: assoc[$'\n\'']++ : bad array subscript (error token is "assoc[$'\n\'']++ ") bash-5.1$ (( assoc[${y@Q}]++ )) bash-5.1$ bash-5.1$ shopt -s assoc_expand_once bash-5.1$ bash-5.1$ (( assoc[${x@Q}]++ )) bash-5.1$ (( assoc[${y@Q}]++ )) bash: ((: assoc['x],b[$(uname >&2)0']++ : bad array subscript (error token is "b[$(uname >&2)0']++ ") bash-5.1$ bash-5.1$ (( assoc[$x]++ )) bash-5.1$ (( assoc[$y]++ )) Linux I tried sh_single_quote like this diff --git a/subst.c b/subst.c index 6132316a..639b18b2 100644 --- a/subst.c +++ b/subst.c @@ -7786,6 +7786,9 @@ string_transform (xc, v, s) case 'Q': ret = sh_quote_reusable (s, 0); break; + case 'S': + ret = sh_single_quote (s); + break; case 'U': ret = sh_modcase (s, 0, CASE_UPPER); break; @@ -7918,6 +7921,7 @@ valid_parameter_transform (xform) case 'E': /* expand like $'...' */ case 'P': /* expand like prompt string */ case 'Q': /* quote reusably */ + case 'S': /* quote reusably */ case 'U': /* transform to uppercase */ case 'u': /* tranform by capitalizing */ case 'L': /* transform to lowercase */ but if assoc_expand_once is enabled it doesn't work with a key that contains a closing brace either. Damn. -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/ > -- Oğuz