Re: Korn Shell Q

From: Green, Simon (Simon.Green@EU.ALTRIA.COM)
Date: Wed Jul 02 2003 - 11:50:30 EDT


Two options, depending on your data.

First:

<your command> | while read TheLine
do
 stuff with $TheLine
done

"read" can run into problems with some other commands, notably rsh so if you
plan to put rsh commands in the loop use the second mechanism. (Actually,
rsh is the only one which has ever given me trouble, but I'm sure there are
more out there.)

Second:

for TheLine in `<your command>` N.B. Back quotes, not normal quotes.
do
 stuff with $TheLine
done

The only problem you might face here is is you have valid word separators in
your data. "for" will take each individual word, not necessarily each line
of data.

Simon Green
Altria ITSC Europe Ltd

AIX-L Archive at http://marc.theaimsgroup.com/?l=aix-l
<http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2> &r=1&w=2
AIX FAQ at http://www.faqs.org/faqs/aix-faq/
<http://www.faqs.org/faqs/aix-faq/>

N.B. Unsolicited email from vendors will not be appreciated.

-----Original Message-----
From: Ranbir Singh [mailto:Singh@XAVIER.EDU]
Sent: 02 July 2003 16:01
To: aix-l@Princeton.EDU
Subject: Korn Shell Q

Hello,

Quick, simple korn shell question:

I have the result of grep and cut commands that shows multiple lines. For
example:

345trh
hur88
kjsdhf
eryyt9
333ret

How can I divide these lines to feed into variables? That is, each of the
above lines needs to be assigned to a variable.



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:59 EDT