LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Bash scripting silly question (http://www.linuxquestions.org/questions/programming-9/bash-scripting-silly-question-552712/)

itz2000 05-09-2007 05:51 PM

Bash scripting silly question
 
hello.. I've found a way to increase lets say a counter... but I think my way is stupid, there must be better solution...

Code:

hey=1
hey=`echo $hey+1 | bc`

I think the best way is something like hey={$$hey}+1
but I'm not familiar with the right syntax.


Thanks.

osor 05-09-2007 05:58 PM

What about
Code:

let hey+=1

osor 05-09-2007 05:59 PM

Alternative:
Code:

hey=$(($hey+1))

jschiwal 05-09-2007 07:24 PM

If it is a loop counter, you can use this form of the "for" command:

for (( index=100; index<200; index++ )); do

osor 05-09-2007 07:32 PM

Oh, I completely forgot about
Code:

let hey++

jlliagre 05-09-2007 07:57 PM

The old (and more portable) way :
Code:

hey=`expr $hey + 1`


All times are GMT -5. The time now is 06:02 AM.