Confused on how to script item

I am working on a script that will parse the /proc/meminfo file and return values. I have been able to pull the MemTotal and MemFree from that file but have stumbled on the next thing I want to do - calculate memory used via subtracting MemFree from MemTotal.

Would I do something like -

memfree=$(more /proc/meminfo | grep MemFree
memtotal=$(more /proc/meminfo| grep MemTotal
Let usedmem=$memtotal-$memfree

echo "Total Memory: $memtotal  Free Memory: $memfree  Memory in use: $usedmem

that? If not, what would be the best method to do this calculation?

usedmem=$((memtotal - memfree))

Remember that cached counts as free, too.

Thank you! I added that to my script and it works.

I'm not sure above will work as the values might have a header with them. Try

grep  ^Mem /proc/meminfo | { read X MEMTOT R;read X MEMFRE R; echo $MEMTOT $MEMFRE $((MEMTOT-MEMFRE)); }

My script is complete and does exactly what I want it to do. Thank you once more!