I wonder if this could actually simplify your commands. I can't test it since I'm not on OSX but I hope it works.
read inMem freeMem totalMem < <(top -l 1 | awk '/PhysMem/ { i = $6; sub(/M/, "", i); f = $10; sub(/M/, "", f); printf("%d %d %d\n", i, f, i + f); exit; }')
echo "inMem: $inMem"
echo "freeMem: $freeMem"
echo "totalMem: $totalMem"