Appending to a variable

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 5
Reputation: mustaine85 is an unknown quantity at this point 
Solved Threads: 0
mustaine85 mustaine85 is offline Offline
Newbie Poster

Appending to a variable

 
0
  #1
Jan 1st, 2009
Hi,
how do you append to a variable? I can only get it to work with a seperate file like this:

printf $number1 >> sum.txt

I tried this :

$number1 >> $sum

but it says $sum: ambiguous redirect, any ideas?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Appending to a variable

 
0
  #2
Jan 1st, 2009
Hey there,

For scripting in shell, you can just concatenate the two variables

sum="hi "
host # number1="there"
host # echo $sum
hi
host # sum="${sum}$number1"
host # echo $sum
hi there
Hope that helps

, Mike
Last edited by eggi; Jan 1st, 2009 at 11:13 pm.
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 5
Reputation: mustaine85 is an unknown quantity at this point 
Solved Threads: 0
mustaine85 mustaine85 is offline Offline
Newbie Poster

Re: Appending to a variable

 
0
  #3
Jan 3rd, 2009
That works great thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Appending to a variable

 
0
  #4
Jan 3rd, 2009
Cool. Glad to help out

. Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC