Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: Found in script; regarding '*0\ rejected*'

Tags:

bash

I'm setting up Check_MK to monitor PowerDNS as well. I found this script and it works fine.

However, I saw *0\ rejected* and *0\ removed* in it:

if  [[ "$REDISCOVER" == *0\ rejected*  &&  "$REDISCOVER" == *0\ removed* ]]; then

I am learning Bash scripting, but I've never seen this before.

Could someone explain what it exactly does?

like image 495
Florius Avatar asked Dec 09 '25 12:12

Florius


1 Answers

When using == within [[ ... ]] in Bash, pattern matching is performed. In your case, the test will pass only if "$REDISCOVER" matches both the patterns *0\ rejected* and *0\ removed* at the same time.

The pattern *0\ rejected* matches strings that:

  • *: are preceded by zero or more characters;
  • 0\ rejected: contain the string 0 rejected (the backslash is used to escape the space, so that it is considered as part of the pattern);
  • *: are followed by zero or more characters.

Or, more simply, [[ "$REDISCOVER" == *0\ rejected* ]] checks whether the variable REDISCOVER contains the string 0 rejected.

Similarly for *0\ removed*.

Examples of valid values for REDISCOVER that will make the test pass are:

0 rejected0 removed           # most simple case;
0 removed0 rejected           # order does not matter;
...0 rejected...0 removed...  # there can be arbitrary garbage before,
                              # between or after the two
like image 114
Andrea Corbellini Avatar answered Dec 12 '25 05:12

Andrea Corbellini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!