Re: more splitting
Bart Schaefer <[email protected]> Tue, 14 Apr 2026 19:02:59 -0700
| Newsgroups | gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user |
|---|---|
| Message-ID | <CAH+w=7a1Z3T2+t5w5Y9_ODFwsDycWfejKSTL9aoukEHhqO8RxQ@mail.gmail.com> |
On Tue, Apr 14, 2026 at 4:24 PM Philippe Altherr <[email protected]> wrote: > > What you try to do is pretty much impossible because when you do 'print -rn $var',you turn the strings in '$var' into a single one Well, you can't do it with just "print" by itself. > How is 'hex' supposed to know which of the spaces in that string were from the strings in '$var' and which ones were introduced to separate the strings in '$var'?!? The trick is to restore some kind of quoting on $var. It's not possible to restore exactly the original quoting but you can do as well as "hex" itself does. If "hex" looks like this ... function hex () { local var element echo if [[ -p /dev/fd/0 ]]; then read -d '' -r var set -- ${(z)var} fi print -rC1 -- ${(q+)${(Q)@}} echo "\n-----------------------------\n" for element ("$@") print -rn -- $element | od -vAx -tx1 -tc } Then: print -rn ${(q+)var} | hex does the same thing as hex ${(q+)var} but you can't avoid that (q+) on the way in to make it sane. More later about $(<&0) ...