LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2010, 02:10 PM   #1
voldemort
LQ Newbie
 
Registered: Oct 2010
Posts: 1

Rep: Reputation: 0
Assigning variable is messing up


I am trying to run this and was into issues

function() {
node=echo "10.11.12.13" | awk '{split ($0, a, "."); print a[1]}'
}

function1() {
function
a=$node
echo $a
echo $a "- 2nd time"
}

This output's first a as 10, that's ok but second a as "0", so i was unable to use it anywhere inscript for second time.

I found the actual issue, but I wanna know why is it so

node=`echo "10.11.12.13" | awk '{split ($0, a, "."); print a[1]}'`
The above line works, but why?

Can someone please help me

Thank you

Last edited by voldemort; 11-05-2010 at 02:11 PM. Reason: missed some lines
 
Old 11-05-2010, 02:26 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Oh He-Who-Must-Not-Be-Named: it's called "Command Substitution".

You can use a=`echo "ABC"`.

You can also use the equivalent a=$(echo "ABC").

'Hope that helps!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Assigning (tail) results to a variable WhisperiN Programming 4 10-17-2009 08:33 AM
Trouble assigning value to variable with fatsheep Programming 1 11-07-2006 07:44 PM
getting rpoblem in assigning value to variable in if construct Ankit mittal Programming 9 01-07-2006 09:12 AM
assigning commands to a variable aunquarra Linux - General 5 01-04-2006 07:58 AM
in C, Assigning output of system() to a variable Miaire Programming 4 01-30-2005 12:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration