I wonder why in the new version of grep (Ubuntu 16.04) my bash script stopped working:
...
COMMIT_REGEX='^\[[A-Z]+-[0-9]+\] \s*\S+(?:.|\n|\r)*\s* \(review: ([a-z]+\.[a-z]+|MYSELF)\)$'
if ! grep -Paz "$COMMIT_REGEX" "$1"; then
...
I get "grep: unescaped ^ or $ not supported with -Pz". I've tried to escape ^ and $ symbols, but it doesn't help.
In Ubuntu 15.10 script works perfectly.
It seems that the problem is the result of a bug with grep -Pz
(credit to Lars Fischer for finding the relevant report).
I would suggest dropping the -P
switch and using -E
instead:
commit_re='^\[[A-Z]+-[0-9]+\] \s*\S+(.|\n|\r)*\s* \(review: ([a-z]+\.[a-z]+|MYSELF)\)$'
if ! grep -qEaz "$commit_re" "$1"; then
The only changes that I've made are to change -P
to -E
and add the -q
(quiet) switch, since you're only interested in the return code. You don't really need a non-capturing group, so I changed it to a normal one.
I also don't like to see ALL_CAPS variable names as they should really be reserved for use by the shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With