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

Can this be done with an array parameter?



    Hi all :)

    I need to process some file contents line-by-line, and I was
going to do it by using a loop, like this:

    cat filename | while read line
    do
        things to do with $line
    done

    Since some of the work would be better done with an array, I
changed this to:

    set -A info
    cat filename | while read line
    do
        info=($info $line)
    done

    This effectively store every line as a separate item in the array
parameter, which surprises me. Lets assume the file contents are:

    A line
    Another line
    Yet another line
    More lines below

    Then the loop will result in (just guessing...):

    info=( A line)
    info=(A line Another line)
    info=(A line Another line Yet another line)
    info=(A line Another line Yet another line More lines below)

    But instead, the 'line' seems to be added *quoted* :?? It's like
Zsh is reading my mind or so. Can anybody explain? As far as I knew,
the more correct way of doing the assignment in the loop, will be:

    index=$(($index+1))
    info[$index]="$line"

    considering 'index' value of '0' at start.

    And my original question: can the array be assigned one line of
the file per slot without the loop?

    Thanks a lot in advance :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



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