Closed dakotahawkins closed 3 years ago
I'm wondering what's the story behind this long regex
I've been using sed -e '/pihole updateGravity/ s/^#*/#/' -i /etc/cron.d/pihole
for some time and it seems to do the job fine
There are simpler ones that do the job, this one is similar to others I've cobbled together to do the same thing.
The line match itself just allows arbitrary whitespace between pihole
and updateGravity
and is case insensitive.
The sed voodoo ${s/^#*/#/;b};$q1
has the following features:
{ }
blocked commands, ending with b
, which does a "Branch to label; if label is omitted, branch to end of script." That enables the following behavior:$q1
it means the replace failed, and the sed exits with a failure. q
is "quit" and 1
is the exit code here.I guess that's not really important unless you're putting it in another script (like I am) and want to respond to failures somehow.
I can change it to the simpler version if you prefer, let me know!
Now that I think about it, for documentation purposes the simpler one is better as long as it continues to work (which it should). I'll just change it to that. I should have considered that in the first place :)
I'm now wondering why did I put a space between / s/
... I don't think there is any reason to put it there
That's important, it's the end of the line match expression and the beginning of the replace. In other words, first it matches the line, then it attempts the replace on matching lines only I think.
Edit: in sed terminology it's the "address"
Also it just occurred to me I need to make sure running that doesn't require a sudo
...
Edit: it does, whoops
Add sed command
sed -Ei '/pihole[[:space:]]+updateGravity/I,${s/^#*/#/;b};$q1' /etc/cron.d/pihole
to the section on disabling the default gravity update schedule.Fixes #67