#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Iran
    Posts
    6
    Rep Power
    0

    Unhappy Help me to write a loop counter


    Hi,
    I very need to write a loop ( containt while or until
    or for ) that can count in ScoUnixOpenserver shell script (bash shell) .
    I try to write a loop like follow but don't work correctly :

    ----------------------------------------------------------------
    #!/bin/bash
    clear
    no=1
    while test $no -le 100
    do
    no=expr $no + 1
    echo $no
    done
    ----------------------------------------------------------------
    enyone can help me .
    thank you for your note.
    F.H.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    USA
    Posts
    334
    Rep Power
    11
    See below for solution. Note the use of backquotes
    to evaluate the expression.

    Also the echo command needs to be before the count
    increment - otherwise the numbers 2 to 101 are output.

    no=1
    while test $no -le 100
    do
    echo $no
    no=`expr $no + 1`
    done

    - Finnbarr

IMN logo majestic logo threadwatch logo seochat tools logo