_egrep_o() function accepts extended regex and on systems that do not have egrep uses sed to emulate egrep. This is failing on the specific regex I was using in dns_freedns.sh. See https://github.com/Neilpang/acme.sh/issues/2305 for the problem I was working on.
The problem is that egrep requires extended regex, and if you pass in non-extended it may fail if there are special characters. But on systems that do not have egrep, the _egrep_o function uses sed to emulate egrep. This fails with the extended regex, but works with the regular regex.
Below script illustrates the problem... I split your _egrep_o function into two to illustrate the problem on systems that have egrep (ie, removed the test for failure with egrep)
#!/usr/bin/env sh
_egrep_o1() {
egrep -o "$1" 2>/dev/null
}
_egrep_o2() {
sed -n 's/.*\('"$1"'\).*/\1/p'
}
txt="<tr><td>example.com</td><tdalign=right><ahref=/subdomain/edit.php?edit_domain_id=1234567>[add]</a></td></tr></table></td></tr>"
echo "Test 1 (grep -o)"
echo "$txt" | grep -o "edit\.php?edit_domain_id=[0-9a-zA-Z]*"
echo "Test 2 (egrep -o with non-extended regex, should fail)"
echo "$txt" | _egrep_o1 "edit\.php?edit_domain_id=[0-9a-zA-Z]*"
echo "Test 3 (sed emulation of egrep -o with non-extended regex, should fail like test 2"
echo "$txt" | _egrep_o2 "edit\.php?edit_domain_id=[0-9a-zA-Z]*"
echo "Test 4 (egrep -o with extended regex, should work"
echo "$txt" | _egrep_o1 "edit\.php\?edit_domain_id=[0-9a-zA-Z]+"
echo "Test 5 (sed emulation of egrep -o with extended regex, should work like test 4"
echo "$txt" | _egrep_o2 "edit\.php\?edit_domain_id=[0-9a-zA-Z]+"
echo "End"
exit
_egrep_o() function accepts extended regex and on systems that do not have egrep uses sed to emulate egrep. This is failing on the specific regex I was using in dns_freedns.sh. See https://github.com/Neilpang/acme.sh/issues/2305 for the problem I was working on.
The problem is that egrep requires extended regex, and if you pass in non-extended it may fail if there are special characters. But on systems that do not have egrep, the _egrep_o function uses sed to emulate egrep. This fails with the extended regex, but works with the regular regex.
Below script illustrates the problem... I split your _egrep_o function into two to illustrate the problem on systems that have egrep (ie, removed the test for failure with egrep)