How to get the total physical memory in Bash to assign it to a variable?

How can I get the total physical memory in bytes of my Linux PC?

I need to assign it to a bash script variable.


grep MemTotal /proc/meminfo | awk '{print $2}'  

The returned number is in KB


phymem=$(awk -F":" '$1~/MemTotal/{print $2}' /proc/meminfo )

or using free

phymem=$(LANG=C free|awk '/^Mem:/{print $2}')

or using shell

#!/bin/bash

while IFS=":" read -r a b
do
  case "$a" in
   MemTotal*) phymem="$b"
  esac
done <"/proc/meminfo"
echo $phymem