LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Assigning variable is messing up (http://www.linuxquestions.org/questions/programming-9/assigning-variable-is-messing-up-842599/)

voldemort 11-05-2010 03:10 PM

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

paulsm4 11-05-2010 03:26 PM

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!


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