Your blob of code aside, don't underestimate the one-liner.
perl -i -pe 's/^sshd_enable=".*?"/sshd_enable="YES"/' /etc/rc.conf
Additionally: If you really want you can even get fancy:
perl -i -pe 's/^sshd_enable="(.*?)"/qq{sshd_enable="} . ( $1 eq "YES" +? "NO" : "YES" ) . qq{"}/e' /etc/rc.conf
In reply to Re: Updating a conf file non-destructively
by Fletch
in thread Updating a conf file non-destructively
by rlb3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |