1

I am trying to understand a piece of code here and as I am not an expert on bash, I am struggling to find out what the below if does:

  if [[ "$4" == *"-a "* ]]; then

I understand the $4 is the fourth parameter, but I am not getting the rest...

Why the condition is between *?

Thank you folks, appreciate any help.

Regards,

Thiago

Thiago Gracioso
  • 81
  • 1
  • 1
  • 6
  • shouldn't it be ${4} instead of $4 ? also, i believe in a bash script you only need one pair of [ and ] ... – clockw0rk Dec 15 '20 at 16:48

1 Answers1

0

[[ is a shell keyword:

$ type [[
[[ is a shell keyword

so it's described in help [[ where it says:

When the `==' and `!=' operators are used, the string to the right of
the operator is used as a pattern and pattern matching is performed.

and in man bash under Pattern Matching it says:

*

Matches any string, including the null string.
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38