Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:08:45+00:00 2026-06-14T13:08:45+00:00

If we can perform this in Perl It would be fine as well. I

  • 0

If we can perform this in Perl It would be fine as well.
I don’t know if this is even possible but this is what i want to be able to do. I am trying to get a memory percentage of memory being used (There may be better ways of doing this, please let me know)

I have this bash command

free -m | grep "Mem: " | awk '{print ($3/$2)*100}' 

This will return a number, but what I want to do is set a variable to the output of the command.

So var1= Output of the above command
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:08:47+00:00Added an answer on June 14, 2026 at 1:08 pm

    I believe this is what you are looking for:

    var1=$(free -m | grep "Mem: " | awk '{print ($3/$2)*100}')
    

    Explanation:

    • The $(...) syntax is called command substitution in shell.
    • It spawns a subshell to execute whatever is inside the parentheses, then returns anything printed out to stdout within that subshell.

    Aside:

    The alternative syntax is with backticks:

    var1=`free -m | grep "Mem: " | awk '{print ($3/$2)*100}')`
    

    but it’s not the preferred method due to readability and nesting issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

at the bash prompt I can perform this copy cp file.txt test1.txt but if
Here is the code, everythin works well except the no application can perform this
How this UIButton rewind can send notification to UIButton play to perform playpauseaction method
Why can't I do this, and how could I perform the same behavior in
How can I perform a shallow syntax check on perl files. The standard perl
Can someone help me rewrite this regex to be non-exponential? I'm using perl to
I want to parse an XML file using Perl . I was able to
I am trying to insure that only one instance of a perl script can
All, I realise against gooogle ToC but I was trying to write a perl
Similar to this question , I am trying to perform simple authentication to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.