Friday 15 May 2015

When dealing with numbers in bash when is [[ ]] preferred over (( )) -


There is a reason to just love something out of curiosity:

  while [[ $ Number -lt 10]]   

more

  while (($ number <10))   

They seem to be doing the same thing; I am thinking that maybe one of them has the benefit of a performance or maybe some portability concerns be with [[]] ?

Neither standard, therefore portability is not an issue. If you are simply doing simple comparisons, there is no difference between it

  if [[$ number -lt 10]]   

and < $ from the other with the ability to drop from one side (because all the stars are assumed) before> if ((number> <10)) < / Pre>

may be variables and derivatives) and readability.

You can like [[... ...] when adding mathematical and non-arithmetic tests to your code:

  If the [[$ $ number -010 & amp; $ File = * .txt]]   

versus

  if ((number & lt; 10)) & amp; Amp; [[$ File = * .txt]]   

You probably want ((...)) if you have some computations in comparison to you:

  if ((number * 2 <10-delta))   

unnecessary complicated vs

  if [[$ ( (Number * 2)) -Lattie $ ((10-delta)]]    

No comments:

Post a Comment