Discussion:
[Help-bash] Why not make ${var@Q} the same as `printf %q' output?
Clark Wang
2017-10-27 09:48:04 UTC
Permalink
See following example:

$ var=123
$ echo ${***@Q}
'123'
$ printf '%q\n' $var
123
$
$ var='1 2 3'
$ echo ${***@Q}
'1 2 3'
$ printf '%q\n' "$var"
1\ 2\ 3
$

Any particular reason to implement them differently?

-clark
Chet Ramey
2017-10-27 18:36:07 UTC
Permalink
Post by Clark Wang
$ var=123
'123'
$ printf '%q\n' $var
123
$
$ var='1 2 3'
'1 2 3'
$ printf '%q\n' "$var"
1\ 2\ 3
$
Any particular reason to implement them differently?
It wasn't a great decision to use backslash quoting with printf %q, but
it's been that way for a long time and I'd rather not change it. The
transformation operators all use single quoting to quote when needed,
and I think that works better.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://cnswww.cns.cwru.edu/~chet/
Loading...