blaze
February 7, 2001, 4:57pm
1
Simple script trying to increment a counter within an echo statement never gets past 1 - PLEASE HELP!
Thanks.
\#!/bin/sh
stepup\(\)
\{
STEP=\`expr $STEP \+ 1\`
echo $STEP
\}
\#
\# Initialize variables
\#
STEP=0
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
echo "Counter Value: \`stepup\`"
PxT
February 7, 2001, 7:09pm
2
the problem is that your function "stepup" gets evaluated at the beginning of execution. I would do something like this instead:
#!/bin/sh
stepup()
{
let STEP=$1+1
echo $STEP
}
STEP=0
STEP=`stepup $STEP`
echo "Counter: $STEP"
STEP=`stepup $STEP`
echo "Counter: $STEP"
STEP=`stepup $STEP`
echo "Counter: $STEP"
STEP=`stepup $STEP`
blaze
February 8, 2001, 10:59am
3
Is there any way to evaluate the function "stepup" and echo/print it out in one statement or are we stuck doing 2 separate statements - one to evaluate the function and another to display it. Is there a way to do it within the function (ie, return)?
Thanks.