Today, when you run the If judgment in the script, you always get into the corresponding branch and check the regular expression without errors. In the shell alone to execute or show no match. Rather strange, it was searched, it was found in the =~ after the regular expression can not be added to the quotation marks, and the point to represent any character, the last is not add (.) * To match the end of the answer.
Here are some of the information that you have searched for:
A test that matches the IP address, and the result does not match:
Newip=' 192.168.1.1 '"$newip]];' Found the IP address 'fi
I have searched the Chinese data in Google and found no problem. Finally, in English, I searched for an article in the "Advanced Bash-scripting Guide" that introduced the Bash version, which wrote:
The =~ Regular Expression match operator no longer requires quoting
of the pattern within [[...]].
Replace the test conditions with the following so that it succeeds.
"$newip=~ ^([0-9]{1,3}.) {3}[0-9]{1,3}]; Then .... fi
When using variables, you can use quotation marks:
Newip=' 192.168.1.100 'reg=' ^ ([0-9]{1,3}.) {3} [0-9] {1,3}$ '$newip]];' Found the IP address 'fi
However, for $reg
this variable, in the [[]]
operator, you cannot add double quotes, otherwise it will not match.
Shell script in the case of the if conditional regular expression =~ quotation mark problem