zshassociative-arrayassociative

Zsh filling associative array with read from file leads to strange separation


I have a textfile generated by find Path -printf '%s\t%p\n' > textfile When I do

 declare -A DICT;
 while IFS='\t' read -r SIZE PFAD
 do DICT[$SIZE]=$PFAD
 done < ../Listen/textfile

the content of DICT surprises me:

print "${(@k)DICT}" shows, that the keys of DICT are not just the SIZE of the files, but consist of SIZE\tRoot_of_PFAD/2_letters_of_following_directory. The values contain the rest of the line = Rest of the path with the filename. Looks to me as if read separates the lines by '\t+9 characters'


Solution

  • IFS=$(printf '\t')
    

    seems to have done the trick. @Gairfowl hinted in the right direction. I hadn't grasped, that the tenth character in the path was a t. Thank you very much!