Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-01-2009
Member
 
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
Reply With Quote
  #2  
Old 10-01-2009
Member
 
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
Reply With Quote
  #3  
Old 10-01-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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
Reply With Quote
  #4  
Old 10-01-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 12:02 AM.