Trepan-Debuggers / zshdb

gdb-like "trepan" debugger for zsh
GNU General Public License v3.0
295 stars 23 forks source link

IFS in Array initialization not handled correctly #7

Closed rjmccabe3701 closed 5 years ago

rjmccabe3701 commented 8 years ago

Consider the simple zsh script:

#!/bin/zsh

arr=($(echo -e "1\n2\n3"))

for temp in ${arr[@]}
do
    echo "temp = $temp"
done

This has the obvious output when run outside zshdb:

temp = 1
temp = 2
temp = 3

When run within zshdb the output is this:

temp = 1
2
3

i.e. the arr array variable now only has a single element.

I ran the same script (changing #!/bin/zsh to #!/bin/bash) in bashdb and it works as expected.

I'm running on ubuntu 14.04 with

% zsh --version
zsh 5.0.2 (x86_64-pc-linux-gnu)
rocky commented 8 years ago

The bug seems to be how IFS is set when run from zshdb. To see this consider simpler program:

arr=($(echo -e "1 2 3"))
typeset -p arr

When run from zsh you get:

typeset -a arr
arr=( 1 2 3 )

while inside zshdb you get:

(/tmp/zshbug.sh:1):
arr=($(echo -e "1 2 3")) 
zshdb<4> c
typeset -a arr
arr=( '1 2 3' )

Explicitly setting IFS helps in the above. That is. changing the program to:

IFS=" "
arr=($(echo -e "1 2 3"))
typeset -p arr

fixes the problem.

I won't have time in the near future to track this down further.

rocky commented 5 years ago

Sorry for the delay. Better late than never I suppose - think of the children.