Re: more splitting

Philippe Altherr <[email protected]> Wed, 15 Apr 2026 01:24:33 +0200
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CAGdYchuXfLZNBY2r8ztKuBrP17BN9UZ-jy_pOXtTHUesyMCL3Q@mail.gmail.com>
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 where the strings
from '$var' are separated by spaces. 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'?!?

Below is a version where both, 'hex $var' and 'print -rN $var |
hex', produce the same result. It expects the stdin to contain strings
separated by NUL characters. That's why the print call has to use the -N
option to join its arguments with NUL characters instead of spaces.

function hex ()
{
  if [[ -p /dev/fd/0 ]]; then
    local var=(${(0)"$(<&0)"})
    echo
    print -rC1 -- ${(q+)var[@]}
    echo "\n-----------------------------\n"
    for element ("$var[@]") print -rn -- $element | od -vAx -tx1 -tc
  else
    echo
    print -rC1 -- ${(q+)@}
    echo "\n-----------------------------\n"
    for element ("$@") print -rn -- $element | od -vAx -tx1 -tc
  fi
}

Philippe