the following code goes into infinite loop and does not increment variable i

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrityunjay11
    New Member
    • Jul 2007
    • 26

    the following code goes into infinite loop and does not increment variable i

    the code is as

    #!/bin/sh

    i=1;
    while [ $i -le 5 ]
    do
    echo "welcome $i times";
    i= 'expr $i + 1 ';
    done


    the give code goes into infinite loop and doesnot increment the variable i



    exit 0;
  • rakeshzingade
    New Member
    • Dec 2007
    • 3

    #2
    hey the code is OK

    just put `` instead of '' for expr

    i=`expr $i + 1`

    after changing the script will give you exact output
    welcome 1 times
    welcome 2 times
    welcome 3 times
    welcome 4 times
    welcome 5 times

    Comment

    Working...