assign value to var

Posted on 2012-08-27
Last Modified: 2012-08-28
How to assign output of awk to variable? following is the line I am trying it is working.

RECOVERY_RBA = echo "$LINE" | awk -F' ' '{ print $3 }
Question by:basirana
    LVL 84

    Accepted Solution

    RECOVERY_RBA=`echo "$LINE" | awk -F' ' '{ print $3 }' `

    RECOVERY_RBA=$(echo "$LINE" | awk -F' ' '{ print $3 }')
    LVL 2

    Assisted Solution


    Ozo's answer is perfectly correct.

    To help you in future endeavors -

    In shell scripting a pair of back ticks (on a US keyboard the key to the left of one) runs the commands between the back ticks and then puts the final output of those commands in place of the commands.


    `echo ls`
    is the same as
    and would actually run the command ls on the current directory.

    Taking the example a little further:

    `echo "I want to run the command ls"|awk '{print $NF}'`
    is the same as

    The syntax $() accomplishes the same result by a slightly different means.  You are calling a variable (hence the $ symbol) and assigning a value to it of the result of the statements within the parenthesis.  This can be integer arithmetic or shell commands.  Either way the result is substituted for the entire $() statement within the shell in the same way that paired back ticks substitute the result to the shell at runtime.

    Best of luck

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
    Recently, an awarded photographer, Selina De Maeyer (, completed a photo shoot of a beautiful event ( in An…
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
    Video by: Phil
    This video goes over how to configure and start a jail in FreeBSD.  This video is meant to supplement the article included with this course.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now