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

Re: more splitting



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



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