2 ms·
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 thi
by sillysaurusx 4y ago
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…
- mmh0000 4y agoTo 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
- Arnavion 4y ago`(( ))` 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.