I need to put the output of a certain command (three lines) in an array, here my script:
#!/bin/sh
while true ;
do
res=($(top -n1 -p $(pidof "$1") | awk '{if (NR==1) print $3} {if (NR==8) print $9"\n"$10 }'));
echo $res[0];
echo $res[1];
echo $res[2];
done;
I have checked this answer but when I run it with sh myScript.sh
I get
myScript.sh: 6: myScript.sh: Syntax error: "(" unexpected (expecting "done")
Am I doing something wrong?