Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:
same as if ((array[i] + 1 != array[i+1])); then foo; fi (as long as $i and array[i+1] contain decimal integers).
– Stéphane Chazelas2 days ago
It produces the value at position [$i] in $array, adds one to it - inside an arithmetic context, then returns (via command substitution) that as the LHS operand to the -ne conditional operator, then evaluates the RHS operand, $(($i + 1)) is variable $i + 1 then the result of this arithmetic operation is used as the key/position in the array ${array[]} - if the LHS and the RHS results are -ne "not equal` the then block runs
– the_velour_fog2 days ago
And also the same as if [[ array[i]+1 -ne array[i+1] ]] ;then foo; fi as both sides of an integer operator are processed as arithmetic expansions. In math: test for A[i]+1 = A[i+1]. Or, in words: is the next array element the consecutive numeric value of the present one?
– BinaryZebra2 days ago
if ((array[i] + 1 != array[i+1])); then foo; fi
(as long as$i
andarray[i+1]
contain decimal integers). – Stéphane Chazelas 2 days ago[$i]
in$array
, adds one to it - inside an arithmetic context, then returns (via command substitution) that as the LHS operand to the-ne
conditional operator, then evaluates the RHS operand,$(($i + 1))
is variable$i + 1
then the result of this arithmetic operation is used as the key/position in the array${array[]}
- if the LHS and the RHS results are-ne
"not equal` thethen
block runs – the_velour_fog 2 days agoif [[ array[i]+1 -ne array[i+1] ]] ;then foo; fi
as both sides of an integer operator are processed as arithmetic expansions. In math: test forA[i]+1 = A[i+1]
. Or, in words: is the next array element the consecutive numeric value of the present one? – BinaryZebra 2 days ago