0

I have a script that prints RAM total memory in gigabytes.

Here is the script:

echo "scale=2; $(sudo awk '/MemTotal/ {print , $2}' /proc/meminfo ) / 1024^2" | bc

and the output of this script is: 11.61

I want to add a string so that output of this script will be something like:

Memory: 11.61GB

How can I do that ?

1
  • You shouldn't need sudo just to read from /proc/meminfo. Commented Feb 15, 2017 at 16:15

1 Answer 1

4

You don't need bc; awk can do math as well, so you can add the desired string to the output of awk.

awk '/MemTotal/ {printf "Memory: %.02fGB\n", $2/1024/1024}' /proc/meminfo
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.