Shell script

Discussion in 'Mac Help/Tips' started by Irishgent, Nov 22, 2002.

  1. Irishgent macrumors newbie

    Joined:
    Nov 14, 2002
    #1
    I just want to increment the value of a variable in a shell script. I have tried

    count = count + 1
    Anyone got any ideas.
     
  2. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #2
    It depends on the shell.

    Bourne shell (sh): count='expr $count + 1'
    C shell (csh): @ count += 1 or @ count++
    Bourne again shell (bash): count = count + 1

    The sh form should work with Korn shell (ksh) and the csh form should work with Tcsh.
     
  3. Irishgent thread starter macrumors newbie

    Joined:
    Nov 14, 2002
    #3
    while, if syntax for tcsh

    I want to make a while loop so in for tcsh.

    What is the correct syntax.

    set count = 1
    set max = 5

    while (count < max)
    do

    increment count by one

    done
     

Share This Page