JavaScript
x
#!/bin/bash
ac = "(free | grep Mem | awk '{print $4/$2 * 100.0}')"
echo "$ac"
I wanted to get the remaining(free) percentage of RAM usage as output storing in variable for further processing. Instead m getting $ac output as
JavaScript
total 0.00
Please help
Advertisement
Answer
JavaScript
#!/bin/bash
ac="$(free | grep Mem | awk '{print $4/$2 * 100.0}')"
echo "$ac"
works fine for me.
(BTW, awk
can do grep’s work too:
JavaScript
free | awk '$1=="Mem:" { print 100*$4/$2; }'
)