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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -