Question:
If the opening parenthesis is synonymous with the test command, then my question arises – why do we need a closing parenthesis?
if [ $a -eq $b ]
Later versions of bash support the [[…]] (reserved word) construct. What are the differences?
Why does an error occur when using […] and several conditions (&&, ||), but when using the construction [[…]], an error does not occur?
if [ $a -eq $b && $c -eq $d ] - ошибка
if [[ $a -eq $b && $c -eq $d ]] - не ошибка
UPD: interpreter #! / Bin / bash is used.
* .Sh format scripts
Answer:
info taken from man bash
.
- let's start with the terminology.
-
[[
Is a compound command ) -
[
andtest
are just builtin commands
-
- a compound command (their list is far from being limited to the
[[
) command is characterized by the fact that its argument can be a compound expression that combines expressions using the following operators (listed in order of priority of calculation):-
( выражение )
– grouping expressions to change the order of evaluation / execution -
! выражение
– "not" -
выражение1 && выражение2
– "and" -
выражение1 || выражение2
– "or"
-
-
the command
[
not exactly a synonym for thetest
command. the syntax for calling them is slightly different, although they are functionally identical:test выражение [ выражение ]
- the built-in commands
[
andtest
have similar, but slightly different syntax, operators for grouping, negation, and logical and / or operations:-
\( выражение \)
– grouping -
! выражение
– "not" (here the syntax is identical) -
выражение1 -a выражение2
– "and" -
выражение1 -o выражение2
– "or"
-