euglug.org

[Eug-lug] Reading data to multiple variables

작성자

카테고리:



Bob MillerWed Jul 28 11:47:53 PDT 2004

Garl Grigsby wrote:

>    I need a bit of bash help. I have a situation where I need to read 
> two pieces of data from a text file and store these data into two 
> variables. I know that this would be easy in perl, but I have to do this 
> as a shell script. The data will be a number and a word, like this: 
> "05e307020000000000000000 Yes".
>    I know that I could simple get the data in two separate operations, 
> but the problem is that there could be either 1, 2, 3, or 4 pairs of 
> data, and while I could still do this will multiple steps, I would 
> prefer to find a more elegant way. What I would really like to do would 
> be to store this data in an array. The problem is that I cannot figure 
> out how to store the data in the array.


This works for me...

	while read line
	do
	    a=($line)
	    echo ${a[*]}
	    echo ${#a[*]}
	done < somefile

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     kbob at jogger-egg.com