DarkKnight DarkKnight - 3 years ago 272
Bash Question

copy shell output to array

i am trying to capture the output of the command fuser into an array in shell script.
based on other similar queries I used below lines in shell.

p_list = ( $("fuser -m /mnt/usb") )

But i am getting below error

./capture.sh: line 8: syntax error near unexpected token `('
./capture.sh: line 8: ` p_list = ( $(fuser -m /mnt/usb) )'

The fuser output is the process list using the above path as below

~# fuser -m /mnt/usb
9261 1089 8526

Why is this issue? Any hints. How to i achieve this.

Answer Source

As with any assignment in bash: no spaces around =.

p_list=( $(fuser -m /mnt/usb) )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download