DarkKnight DarkKnight - 17 days ago 7
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) )