zsh-users
 help / color / mirror / code / Atom feed
* Can this be done with an array parameter?
@ 2004-02-19 16:46 DervishD
  2004-02-19 17:00 ` Peter Stephenson
  2004-02-19 17:16 ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: DervishD @ 2004-02-19 16:46 UTC (permalink / raw)
  To: Zsh Users

    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/


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-02-19 17:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-19 16:46 Can this be done with an array parameter? DervishD
2004-02-19 17:00 ` Peter Stephenson
2004-02-19 17:14   ` DervishD
2004-02-19 17:24     ` Peter Stephenson
2004-02-19 17:41       ` DervishD
2004-02-19 17:16 ` Bart Schaefer
2004-02-19 17:27   ` DervishD

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).