shanenin Posted July 21, 2005 Report Share Posted July 21, 2005 I was helping someone write a bash script. I needed to have a counter in a while loop. in python you can do this x=x+1orx+=1in bash I had to do it this way, I needed to look this upx=`echo "$x + 1" | bc`wow, that just seems rediculous. Also is there a logical reason bash does not use these operaters(<,>,<=,>=) instead it uses (-eq,-ne,it,ie) Quote Link to post Share on other sites
jcl Posted July 21, 2005 Report Share Posted July 21, 2005 You want arithmetic expansion. Syntax is $((expression)).x=$((x+1))or if you're using bash((x++))or evenlet x+=1. All of the normal arithmetic operaters are available, including the comparison operators you mentioned. Quote Link to post Share on other sites
shanenin Posted July 21, 2005 Author Report Share Posted July 21, 2005 those methods work much better then my convoluted mess. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.