Variable increment (of some sort)

i have a variable that has more than one value. i am declaring another variable, which will have the old variable data one by one. i want to use the second variable to hold the track of all the variable it has parsed from the first one. can somebody help me how do i declare and use the second variable?

e.g.

 LIST="A:B C:D E:F"
for VAR in `print $LIST`
do
NAME=`print $VAR | cut -d ":" -f1`
RETURN_VALUE1=`some action`
echo $RETURN_VALUE1
done

i want another variable to keep track of what all LIST variable it has processed and need to display that these values were used

Hi

Something like this?

do
NAME=`echo $VAR | cut -d ":" -f1`
OLDLIST=$OLDLIST" "$VAR
RETURN_VALUE1=`some action`
......

OLDLIST will contain the items parsed.

OLDLIST=$OLDLIST" "$VAR
are both OLDLIST and $OLDLIST going to be that variable?

I don't understand the question.

OLDLIST is the name of the variable.

$OLDLIST is its contents.

SERVERLIST="1:Server_1a 1:Server_1b 2:Server_2a 2:Server_2b 3:Server_3a 3:Server_3b 4:Server_4a 4:Server_4b"
RETURN_VALUE1=0


for VAR in `print $SERVERLIST`
do
SERVERNAME=`print $VAR | cut -d ":" -f1`
SERVER_NAME=`print $VAR | cut -d ":" -f2`

print "<br>BOUNCING $SERVER_NAME on $SERVERNAME<br>"
print "*******************************************<br><br>"

RETURN_VALUE1=`cmd $SERVERNAME ".././ServerBounce.ksh $SERVER_NAME"`
echo $RETURN_VALUE1
done

if [ $RETURN_VALUE1 -eq 0 ] ; then
        print "\nThe $SERVER_NAME was bounced successfully\n"
elif [ $RETURN_VALUE1 -eq 1 ] ; then
        print "\nThe $SERVER_NAME couldn't be stopped\n"
elif [ $RETURN_VALUE1 -eq 2 ] ; then
        print "\nThe $SERVER_NAME couldn't be started\n"
else
        print "\nThe $SERVER_NAME was not bounced\n"
fi
done

this is the code i am using. the called script will bounce the servers from the list.
the idea is to update this script in a webpage and those if-else can't be run and will only display the last server.
hence i want a variable that will hold the information about what all servers were parsed and increment it once the previous server was bounce and at last will print that the following servers (its content) were bounced.

for VAR in `print $SERVERLIST`

useless use of backticks. for VAR in $SERVERLIST will do.

But you don't need to run print and cut in backticks 10 times to process one line of text either. It is extremely slow to run awk/cut/sed 10 times to process 10 single bits of text -- that's like making 10 phone calls to say 10 words. I'd just split in the shell itself:

OLDIFS="$IFS" # Save the default value of the special IFS variable for later.  It controls splitting.

SERVERLIST="1:Server_1a 1:Server_1b 2:Server_2a 2:Server_2b 3:Server_3a 3:Server_3b 4:Server_4a 4:Server_4b"

IFS=": " # Split on space, or :
        set -- $SERVERLIST # $1=1, $2=Server_1a, $3=1, $4=Server_1b, etc.
IFS="$OLDIFS" # Set splitting back to normal

VAR=""

while [ "$#" -gt 0 ] # Loop until $1, $2, ... are empty.  We remove two arguments per loop.
do
        # Append new result to VAR.  If VAR was "1" before, it'll be "1 2", etc.
        VAR="$VAR $(cmd $1 ".././ServerBounce.ksh $2")"
        shift ; shift # Get rid of $1, $2, and shift down so the list starts at $1 again.
done

# $1 will be the result from the first process, $2 is the result from the second, etc.
set -- $VAR
echo "$# results in list"
echo "First is $1"
echo "Second is $2"
...

thanks for the insight. but i am still new to unix scripting.
NEWLIST=$NEWLIST" "SERVER_NAME
the above statement will be inside the for loop and will get append with new SERVER_NAME every time.
my question is how do we determine how many values NEWLIST is holding? is there any wc -l stuff we can do inside a variable?
value of NEWLIST="Server_1a Server_1b Server_2a Server_2b Server_3a Server_3b Server_4a Server_4b""

Please read my code. It shows you how to do exactly that. It even shows you how to loop over the contents of a list -- for X in $NEWLIST

The code you gave:

NEWLIST=$NEWLIST" "SERVER_NAME

is wrong. Without the $ in front of SERVER_NAME, it will append the string SERVER_NAME to the list, not the variable.

You'll end up with a list of "SERVER_NAME SERVER_NAME SERVER_NAME SERVER_NAME"