I feel I am close to solving this, but can't quite get there.
I have a script that searches to see if a utility is called in /etc/rc.local
. If it isn't, I want to add a line calling it to the line just before exit 0
at the end of the file. So far, I have this:
sudo sed -i 's/.*exit 0.*/'$UTILITY_PATH'\n&/' /etc/rc.local
This kind of works, but also matches lines with "exit 0" as a comment - which occurs further up /etc/rc.local
as a reminder to users to ensure that the script should end with this line.
So, to be clear, the following should match:
exit 0
exit 0
exit 0
and so forth. The following should NOT match:
#exit 0
# exit 0
# blah blah "exit 0" blah blah
# exit 0
Can anyone point me in the right direction?