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
Post a Comment