Unix command procedure help........

adamooten
adamooten used Ask the Experts™
on
I am trying to write a command procedure to compute the sum from 1 squared to $i squared.  I am very new to Unix, & trying to teach myself.  Here is what I have, and it does not work:

set $i=0
set $sum=0
for $i -lt 1
do
     sum='expr $sum +'$i'*'$i'
     i='expr $i-1'
done
echo $sum

I don't know how to ask the user for the i variable or if I am declaring them right???
Be nice I'm a Unix newbie...
Adam
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2014
Top Expert 2015
Commented:
echo enter i
read  i
sum=0
while [ $i -ge 1 ]
do
    sum=`expr $sum + $i \* $i`
    i=`expr $i - 1`
done
echo $sum

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by ozo

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial