[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

assign value to var

Posted on 2012-08-27
2
Medium Priority
?
533 Views
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 }
0
Comment
Question by:basirana
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 500 total points
ID: 38339101
RECOVERY_RBA=`echo "$LINE" | awk -F' ' '{ print $3 }' `

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

Assisted Solution

by:stevaleelee
stevaleelee earned 500 total points
ID: 38340306
Basirana,

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.

Example:

`echo ls`
is the same as
ls
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
ls

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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

831 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