Sign in to follow this  
shanenin

Bash Is Goofy

Recommended Posts

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+1

or

x+=1

in bash I had to do it this way, I needed to look this up

x=`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)

Share this post


Link to post
Share on other sites

You want arithmetic expansion. Syntax is $((expression)).

x=$((x+1))

or if you're using bash

((x++))

or even

let x+=1

. All of the normal arithmetic operaters are available, including the comparison operators you mentioned.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this