help-bash
[Top][All Lists]
Advanced

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

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


From: Dallas Clement
Subject: [Help-bash] populating an array with piped output in a loop
Date: Mon, 28 Nov 2011 17:55:56 -0600

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?

Thanks



reply via email to

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