I'm reasonably proficient with regexes, but I'm having trouble with doing something simple in a Bash script.
I'm working with the following script excerpt:
if [[ "$message" =~ "^The node was low on resource: ephemeral-storage.*$" ]]; then
message="ephemeral storage"
elif [[ "$message" =~ "^The node was low on resource: memory.*$" ]]; then
message="memory"
elif [[ "$message =~ ^The node was low on resource: \[DiskPressure\].*$" ]]; then
message="disk"
else
echo "No match"
fi
If the value in "message" begins with "The node was low on resource: ephemeral-storage. Container ...", this matches the LAST expression. I've been staring at this for quite a while, and I'm just not getting it.
I turned on verbose mode in the script, and I see the following in the output:
+ [[ The node was low on resource: ephemeral-storage. Container ... =~ \^The node was low on resource: ephemeral-storage\.\*\$ ]]
+ [[ The node was low on resource: ephemeral-storage. Container ... =~ \^The node was low on resource: memory\.\*\$ ]]
+ [[ -n The node was low on resource: ephemeral-storage. Container ... =~ ^The node was low on resource: \[DiskPressure\].*$ ]]
+ message=disk
Note two things in this output. I'm eliding much of the value that's in the "message" variable with "...". Second, I see the "-n" on the output from the last elif. Clearly, that's not in my code, not explicitly. Checking the docs, I see the "-n" operator returns true if the string operand length is non-zero. So, if that's the code that's being executed, I can see why it's considering the last condition to be true, but I don't understand what it's doing here.