Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending a variable

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US
In Sunos Ksh ...
if iplist contains a list of ip address :

while read ips
do
$nlist=`echo $ips`
echo "$nlist"
done < iplist


every time through the loop, $nlist is rewritten.
I want to append a variable with every iteration through the loop instead of rewriting it. (although wrong) something like this ..

echo $nlist >> $finallist


Thanks alot
 
Something like this ?
while read ips
do
nlist="$nlist $ips"
echo $nlist
done < iplist

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How about...
Code:
#!/bin/ksh

export FINALLIST=$(cat iplist | tr '\n' ' ')

print ${FINALLIST}
That puts each line in the file one one line in the variable, separated by spaces.
 
UUOC Police!

Code:
#!/bin/ksh

export FINALLIST=$(tr '\n' ' ' <iplist)

print ${FINALLIST}


HTH,

p5wizard
 
[rednose]

Code:
#!/bin/ksh

export FINALLIST=$(cat iplist | cat | cat | cat | cat | tr '\n' ' ')

print ${FINALLIST}
 
Watch it Sam!!!

Or I'll have you repeat 100 times: "I will not use cat unnecessarily in shell scripts" [robocop]


HTH,

p5wizard
 

Works great .. thanks ...sometimes I just can "see" it ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top