storing values in arrays using shell

Friends,
I have to execute a command and store its contents into an array using shell. this is what i have tried
#!/bin/bash

disk_names = ($(`iostat -xtc | egrep -v "device|nfs[0-9]" | awk '{print $1}'| tr '\n' ' ' `))

But its throwing an error message as

./test-script
./test-script: line 3: syntax error near unexpected token `('
./test-script: line 3: ` disk_names = ($(`iostat -xtc | egrep -v "device|nfs[0-9]" | awk '{print $1}'| tr '\n' ' ' `))'

Can any one correct me with the correct script please.

you have both $() and backticks. You need one or the other.

disk_names = ($(iostat -xtc | egrep -v "device|nfs[0-9]" | awk '{print $1}'| tr '\n' ' ' ))

or

disk_names = (`iostat -xtc | egrep -v "device|nfs[0-9]" | awk '{print $1}'| tr '\n' ' ' `)

You need to assign array values in a loop. Also, the grep | awk | cut can be done in awk in one shot. Can you post a typical o/p of iostat?

actually ripat, this will work:

test=($(ls));echo $(ls);echo ${test[1]}

no loop necessary

I stand corrected for the loop. But that piping is a waste of resources. awk can "grep" and "cut" if properly used.

What's the OP iostat o/p ?

iostat -xtc
extended device statistics tty cpu
device r/s w/s kr/s kw/s wait actv svc_t %w %b tin tout us sy wt id
sd0 8.1 4.9 65.2 540.8 0.0 0.7 54.2 0 2 0 4 0 1 0 99
sd1 0.0 0.0 0.3 0.0 0.0 0.0 0.5 0 0
nfs1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
nfs2 0.1 0.0 4.6 0.0 0.0 0.0 14.0 0 0

Try:

iostat -xtc | awk '!/device|nfs[0-9]/ {printf "%s ",$1}'