News for hackers. Stuff that matters.
Re:Bash Retry Function with Exponential Backoff by sillysaurusx on Thursday December 29, 2022 @05:53PM (#34179206)
Whoa. No dollar signs at all?

I’m at Lowes — does ((i+1)) work? Or is it just for incrementing / decrementing (which is still very useful!)

EDIT: thinking this over, does this work for variable substitution too? E.g. ((i)) being equivalent to $i. Not that you’d necessarily want to…

Re:Bash Retry Function with Exponential Backoff by Arnavion on Thursday December 29, 2022 @06:04PM (#34179321)
`(( ))` is an arithmetic evaluation block. Its content has to be an arithmetic expression. Arithmetic expressions don't require `$` before simple variable names and some more complex expressions like array indexing.

`(( i + 1 ))` will evaluate the result of adding one to `$i` and then throw away the result. It doesn't do anything useful (other than having a different exit code depending on whether the expression evaluated to 0 or not).

`$(( ... ))` evaluates the expression and then returns its value. ie `i=$(( i + 1 ))` will increment `$i`, just like `(( i++ ))` did.

Re:Bash Retry Function with Exponential Backoff by mmh0000 on Thursday December 29, 2022 @05:55PM (#34179220)
To add arbitrary numbers, you'd have to do an assignment, like this:

  [mmh@x670]$ ((i=i+2)); echo $i
  6
  [mmh@x670]$ ((i=i+2)); echo $i
  8