euglug.org

[Eug-lug] Reading data to multiple variables

작성자

카테고리:



Garl GrigsbyWed Jul 28 11:33:26 PDT 2004

    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. I've tried something like this:

    myarray[*] = awk `my awk foo`

or this

    myarray[*] = awk `my awk foo`

but bash complains about a bad array subscript. So does anybody feel 
like learning me some bash?

Thanks,
Garl