LinuxQuestions.org
Visit Jeremy's Blog.
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, 03: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 03:11 PM. Reason: missed some lines
 
Old 11-05-2010, 03:26 PM   #2
paulsm4
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:33 AM
Trouble assigning value to variable with fatsheep Programming 1 11-07-2006 08:44 PM
getting rpoblem in assigning value to variable in if construct Ankit mittal Programming 9 01-07-2006 10:12 AM
assigning commands to a variable aunquarra Linux - General 5 01-04-2006 08:58 AM
in C, Assigning output of system() to a variable Miaire Programming 4 01-30-2005 01:40 PM


All times are GMT -5. The time now is 10:16 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration