The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple addition, help. Bandit390 Shell Programming and Scripting 3 09-23-2008 11:46 AM
addition email-lalit Shell Programming and Scripting 2 08-06-2008 02:58 PM
Addition problem onlyroshni Shell Programming and Scripting 2 12-10-2007 11:11 AM
How to perform addition of two numbers in shell scripting in Solaris-10 krevathi1912 SUN Solaris 9 11-29-2007 06:36 AM
floating point addition ravi raj kumar Shell Programming and Scripting 8 12-21-2006 11:47 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-28-2008
cfg cfg is offline
Registered User
 

Join Date: Sep 2008
Posts: 4
addition in sh shell

I have to create un counter and I am unable to do an additition:

#!/bin/sh
count=$1
while [[ $count -le 10]]
do
echo $count
$count=$count+$1
done
Reply With Quote
Forum Sponsor
  #2  
Old 09-28-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
The [[ ... ]] test command is not portable with all shell versions, try this:

Code:
#!/bin/sh

count=$1
while [ "$count" -le 10 ]
do
  echo "$count"
  let count="count+$1"
done
BTW there must be a space between the test statement and the brackets.

Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0