Uno=1
Dos=2
# aquí la salida es S
if (( Uno < Dos )); then echo S; else echo N; fi
# aquí la salida es N
if [[ Uno < Dos ]]; then echo S; else echo N; fi
Uno=1
Dos=2
# aquí la salida es S
if (( Uno < Dos )); then echo S; else echo N; fi
# aquí la salida es N
if [[ Uno < Dos ]]; then echo S; else echo N; fi
(( expresión ))
allows you to evaluate arithmetic expressions . If the value of the expression is non-zero, the return status is 0; otherwise, the return status is 1.[[ expresión ]]
is a bashism (something Bash-like, while[
generic -- you can read about the difference between[
and[[
) and is used to evaluate expressions, which can be much more complex than arithmetic.So when you say
(( uno < dos ))
, the interpreter looks at the value of$uno
y$dos
and evaluates which is greater.However, when you say
[[ uno < dos ]]
, the interpreter lexicographically evaluates the strings "one" and "two" and determines that "one" is not greater than "two".To evaluate the content of the variables in
[[
you must use$
so that its value is expanded:Where
-lt
means "lower than", that is, less than . In total they are: '-eq', '-ne', '-lt', '-le', '-gt' and '-ge'.For example:
When you use square brackets you have to use different syntax, i.e.:
Brackets allow you to enter console commands.