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

more splitting



Stephane showed me this for getting a handle on how things are splitting, and showing a parallel hex dump:

function hex ()
{
local var
if [[ -p /dev/fd/0 ]]; then
    read var
    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

}

    ... works fine with an argument, but with a pipe things go missing::

    Run:

 % var=("a b" c$'\n''d e f'' ''g h')

 %  hex $var

'a b'
$'c\nd e f g h'

-----------------------------

000000  61  20  62
         a       b
000003
000000  63  0a  64  20  65  20  66  20  67  20  68
         c  \n   d       e       f       g       h
00000b

    ... very nice.  But:

% print -rn $var | hex  
                    
'a b c'

-----------------------------

000000  61  20  62  20  63
         a       b       c
000005

    ... I've kept symmetry between both methods but something goes wrong at the newline.  I know it's all there, just a question of teasing it out of hiding.  





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