From: DervishD <raul@pleyades.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Can this be done with an array parameter?
Date: Thu, 19 Feb 2004 17:46:31 +0100 [thread overview]
Message-ID: <20040219164631.GB2804@DervishD> (raw)
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/
next reply other threads:[~2004-02-19 16:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-19 16:46 DervishD [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040219164631.GB2804@DervishD \
--to=raul@pleyades.net \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).