Results 1 to 4 of 4

Thread: Help with sh script loop counting

  1. #1
    Join Date
    Oct 2008
    Posts
    47

    Help with sh script loop counting

    This is mainly using scripts using bash as interpreter and as a result of using the at command I have to meter sh. But I can not so I ask for your help.

    This is my bash script that works well:
    Code:
    #!/bin/bash 
    
    a=0
    
    while [ $a -ne 10 ]
    do 
    echo $a >>/dev/pts/0
    (( a = a +1 ))
    done 
    exit 0
    It therefore gives 0,1,2,3,4,5,6,7,8 and 9.

    and I would do the same thing in sh unfortunately it does not:
    Code:
    (( a = a + 1 ))
    So if someone knows an equivalent in sh

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Help with sh script loop counting

    Already, for my part, for bash, I use:

    a = $(( a + 1 ))
    (or a=$(( $a + 1 )) I know more)

    testing to see


    EDIT, I do not know if both operate bash shell
    REED: it works on this test:
    Code:
     #!/bin/sh 
     # 
    
      i=0 
      while true, do i=$(( $i + 1)) ; echo $i ; done

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Help with sh script loop counting

    Code:
    #!bin/sh
    for((a=0;a<=10;a++)
    do 
    echo ${a}>/dev/pts/0
    done
    OR
    Code:
    #!bin/sh
    for a in $(seq 0 1 10)
    do 
    echo ${a}>/dev/pts/0
    done
    finally ... there's lots of solutions

  4. #4
    Join Date
    Oct 2008
    Posts
    47

    Re: Help with sh script loop counting

    That was the exact answer to my question.
    Thank you for the quick responses.

Similar Threads

  1. Watercooling: Single loop or Dual Loop
    By Akolekar in forum Hardware Peripherals
    Replies: 3
    Last Post: 21-10-2011, 10:52 PM
  2. Excel Macro to loop a script
    By JFN in forum Software Development
    Replies: 1
    Last Post: 27-04-2010, 10:06 AM
  3. Loop counting odd and even numbers
    By Allan.d in forum Software Development
    Replies: 3
    Last Post: 23-10-2009, 11:40 AM
  4. VB script - GOTO Do Loop - possible to acheive?
    By Bosch in forum Software Development
    Replies: 5
    Last Post: 12-01-2009, 08:25 PM
  5. How to create a script in a DOS batch file to do a loop?
    By Jon Osborn in forum Windows Server Help
    Replies: 2
    Last Post: 27-05-2008, 06:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,167,602.83342 seconds with 16 queries