Re: [Help-bash] populating an array with piped output in a loop
From:
Greg Wooledge
Subject:
Re: [Help-bash] populating an array with piped output in a loop
Date:
Tue, 29 Nov 2011 09:22:11 -0500
User-agent:
Mutt/1.4.2.3i
On Mon, Nov 28, 2011 at 05:55:56PM -0600, Dallas Clement wrote:
> 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?
Convert the pipeline into a process substitution:
while read -r line; do
disks[counter]=${line##*=}
disks_name[counter]=${line%%=*}
counter=$((counter+1))
done < <(grep "^disk[0-9]*=" /etc/diskinfo)