help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] populating an array with piped output in a loop


From: Clark J. Wang
Subject: Re: [Help-bash] populating an array with piped output in a loop
Date: Tue, 29 Nov 2011 22:24:42 +0800

On Tue, Nov 29, 2011 at 07:55, Dallas Clement <address@hidden> wrote:
Hi All,

I understand the reason the following snippet of code will not work
because the pipe invokes a sub-shell.

       COUNTER=0
       DISKS=()
       DISKS_NAME=()
       grep "^disk[0-9]*=" /etc/diskinfo |
       while read LINE;
       do
               DISKS[${COUNTER}]=`echo ${LINE}|sed -e "s/.*=//"`
               DISKS_NAME[${COUNTER}]=`echo ${LINE}|sed -e "s/=.*//"`
               COUNTER=$((${COUNTER} + 1))
       done

What is the best way to populate an array with the contents of a file
when you need to transform each line read from the file?

while read LINE; do ...; done <  <(grep ...)
 

Thanks




--
-Clark


reply via email to

[Prev in Thread] Current Thread [Next in Thread]