I am trying to store Available and Total Memory into variables in a script file as follows,
read -r Available Total <<EOT
$(free -m | awk '/^Mem/{print $7; print $2;}')
EOT
$ echo $Total
$ echo $Available
1437
But I am unable to store the variable $Total.
But when I do:
$ read Available Total <<EOT
$(echo $(free -m | awk '/^Mem/{print $7; print $2;}'))
EOT
$ echo $Available
1309
$ echo $Total
7865
It works. But shellcheck gives me following suggestion:
Useless echo? Instead of 'echo $(cmd)', just use 'cmd'. [SC2005]
Why the forst example didn't work? and Why the second one works?