Re: more splitting

Ray Andrews <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <[email protected]>
On 2026-04-14 20:26, Bart Schaefer wrote:
> If you redo 'hex' to accept the name of the variable instead of the
> expansion of the variable, you can fix all of this:
>
> function hex ()
> {
>      local _hex_var element
>      echo
>      if [[ -p /dev/fd/0 ]]; then
>         read -d '' -r _hex_var
>      else
>         _hex_var=$1
>      fi
>      set -- ${(P)_hex_var}
>      print -rC1 -- ${(q+)${(Q)@}}
>      echo "\n-----------------------------\n"
>      for element ("$@") print -rn -- $element | od -vAx -tx1 -tc
> }
>
> hex var
> print var | hex
Perfect!  If the *name* is passed, then it doesn't matter if it's a data 
stream.  I trust a name is always a string, so front door or back door 
... all the same.  I hope my comments are correct:

# Test variable:
var=("a b" c$'\n''d e f'' ''g h' ij)

# % hex var
# % print var | hex
# We pass the NAME of the array variable thus the pipe || argument 
methods work exactly the same. If we passed the value of the array 
instead, the pipe would lose all splitting information, turning it into 
a string. Yes? Bart knows these things.
function hex ()
{
     local _hex_var element
     echo
     if [[ -p /dev/fd/0 ]]; then  # We are smoking a pipe.
        read -d '' -r _hex_var   # -d:terminate on nul, -r:'raw'--all 
literal.
     else
        _hex_var=$1             # We receive the NAME of the var :-) tx. 
Bart
     fi
     set -- ${(P)_hex_var}        # Expand PPs to value of named var.
     # (q+):quote the quotes ... sorta, -C1: columns split on spaces.
     print -rC1 -- ${(q+)@}
     echo "\n-----------------------------\n"
     for element ("$@") print -rn -- $element | od -vAx -tx1 -tc
}

... but many questions running the thing ...

On Tue, Apr 14, 2026 at 8:26 PM Bart Schaefer<[email protected]> wrote:

>      print -rC1 -- ${(q+)${(Q)@}}

Sorry, there's an extra (Q) in there, should be just
     print -rC1 -- ${(q+)@}

Too much copy-pasting.

That was one of my questions :-)
Already fixed above.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.