LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script text line into an array (https://www.linuxquestions.org/questions/programming-9/bash-script-text-line-into-an-array-333174/)

toolshed 06-13-2005 02:12 PM

Bash script text line into an array
 
I am trying to read a command and pipe each line into an array.

I want to read:
$chkconfig --list

After I read that command I want to parse each line into 2-d array.
I figure out out to get first line with awk, but not sure how to make it loop till EOF.

$chkconfig --list, when output is just one big text word. It does not preserve the newlines. I wish I token on newlines instead "6:off", because we know runlevel 6 will be off(or should be)


Anyone got in good resources I could look at?

dub.wav 06-13-2005 05:49 PM

This might work:

Code:

chkconfig --list | while read line
do
  arr=($line)
done

or

Code:

chkconfig --list | while read line
do
 set -- $line # and use $1, $2, $3, etc instead of array indexes.
done



All times are GMT -5. The time now is 07:26 PM.