Create variable named variable$i in for loop

145 views
Skip to first unread message

grey...@zerobyte.org

unread,
Sep 24, 2003, 7:01:36 PM9/24/03
to
I'm obviously missing something. I have written a simple
shellscript that performs a number of tests in a for loop. In each
instance, I would like to log a count of how many successes the test
encountered to then echo at the end. I'm doing it this way:

limit=$1
for i in A B C D E
do
counter=0
success=0
fail=0
while [ $counter -lt $limit ]
do
CHKIT $i > tmpfile
counter=`expr $counter + 1`
if [ -s tmpfile ]
then
success=`expr $success + 1`
echo "$i Success: " $success
rm tmpfile
else
fail=`expr $fail + 1`
echo "$i Failure: " $fail
fi
done
success$i=$success
done
echo "SUMMARY:"
echo "A Successes:" $successA
echo "B Successes:" $successB
echo "C Successes:" $successC
echo "D Successes:" $successD
echo "E Successes:" $successE

The error I'm getting would seem to suggest that rather than
assigning variable, for example, successA=6, it is attempting to
execute that. The error is:

UX:sh (BATCHCHK): ERROR: successA=6: Not found

Can someone tell me where I'm going wrong? TIA.

Barry Margolin

unread,
Sep 24, 2003, 7:10:12 PM9/24/03
to
In article <j464nvo9suecu03qs...@4ax.com>,

<grey...@zerobyte.org> wrote:
> I'm obviously missing something. I have written a simple
>shellscript that performs a number of tests in a for loop. In each
>instance, I would like to log a count of how many successes the test
>encountered to then echo at the end. I'm doing it this way:

This is what arrays are for.

But if you really want to do what you tried to write, use "eval":

eval sucess$i=$success

--
Barry Margolin, barry.m...@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Reply all
Reply to author
Forward
0 new messages