linux - Why can't I assign the value returned by grep to a variable? -


i have tried:

total_mem= $(grep memtotal /proc/meminfo | awk '{print $2}') total_mem= 'grep memtotal /proc/meminfo | awk '{print $2}'' total_mem= grep memtotal /proc/meminfo | awk '{print $2}' 

and every time call:

echo "total memory available: " $total_mem 

it returns blank.. did miss?

cred anubhava posting first, here way it:

total_mem=$(awk '/memtotal/ {print $2}' /proc/meminfo) 

does not work since there space after =

total_mem= $(grep memtotal /proc/meminfo | awk '{print $2}') 

does not work since there space after = , wrong quoting. use parentheses or backtics. (best use parentheses)

total_mem= 'grep memtotal /proc/meminfo | awk '{print $2}'' 

does not work since there space after = , missing quoting.

total_mem= grep memtotal /proc/meminfo | awk '{print $2}' 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -