Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

print -D and ${(D)} quoting

I noticed, via cdr, that the file "/home/pws/with space" turned into
"~/with space" when you used "print -D".  This seems to me wrong --- as
it stands, the first part of the string needs to be used literally when
passed to the shell as an argument for re-evaluation, while the second
part needs to be quoted or it will be split into two words.  So the
result is inconsistent and there's no easy rule by which to interpret
the resulting output.  This isn't specific to space, it's true of any
special character.

As I was thinking about fixing this it occurred to me that most of the
time I can fix it by using tricks with the parameter expansion (D) flag,
although the (D) flag only got added in 28025 in June, which I think is
why I didn't use it before.  They're not completely trivial to do
consistently, however.

Still, the real fix isn't necessarily trivial to do consistently,
either, so that's why I'm asking about it.  In particular, unless I
reorder the code in bin_print(), "-D" processing happens after any
stripping of backslash that happens because -r is not present.  That
looks the wrong way round, certainly if I implement the fix.  What I
mean is, the new behaviour after the basic fix to add quoting is this:

% print -rD "/home/pws/with space"
~/with\ space

(because of -r)

% print -D "/home/pws/with space"
~/with\ space                # actual result
~/with space                 # expected result on general moral principles

So I think I should reverse the order of handling of -D and not--r.  That
may be easier said than done, the logic in bin_print() is somewhat

Presumably if I change print -D I should also change the (D) flag
similarly.  I think that's less of an issue because it's easy to nest
the effects of parameter flags.  Further, quote munging is a more
familiar effect in parameter substitution than it is in "print"

Plan B would be just to change the (D) flag and use that in "cdr -l";
there's no release of the shell with (D) in yet.

Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom

Messages sorted by: Reverse Date, Date, Thread, Author