+ lines=`ifquery $i | grep -v metric | sed 's/://' | sed 's/ /[[:space:]]*/'`
+ sed -i -e "s/\(^iface.*$i.*dhcp\)/#NetworkManager#\1/" $NIF_FILE
+ for line in $lines; do
+ sed -i -e "s/^\([[:space:]]*$line\)/#NetworkManager#\1/" $NIF_FILE
+ done
This relies on two assumptions that may not hold true:
- that the only occurrence of the line in the file is for the interface which is being disabled
- that the contents of the line work in a sed command - i.e., they contain no special characters, including '/', '$', '*'...
I think it would be better to do a single sed command that detects the start and end of the stanza and applies the s/// to all lines in it. E.g.:
+ lines=`ifquery $i | grep -v metric | sed 's/://' | sed 's/ /[[:space:]]*/'` *$i.*dhcp\ )/#NetworkManag er#\1/" $NIF_FILE [:space: ]]*$line\ )/#NetworkManag er#\1/" $NIF_FILE
+ sed -i -e "s/\(^iface.
+ for line in $lines; do
+ sed -i -e "s/^\([
+ done
This relies on two assumptions that may not hold true:
- that the only occurrence of the line in the file is for the interface which is being disabled
- that the contents of the line work in a sed command - i.e., they contain no special characters, including '/', '$', '*'...
I think it would be better to do a single sed command that detects the start and end of the stanza and applies the s/// to all lines in it. E.g.:
sed -i -e"/^[[ :space: ]]*iface[ [:space: ]]\+$i[ [:space: ]]\+.*dhcp/ ,/^[[:space: ]]*\(iface\ |auto\| mapping\ |source\ |allow- \)/ { /^[[:space: ]]*iface[ [:space: ]]\+$i[ [:space: ]]\+.*dhcp/ s/^/#NetworkMan ager#// ; /^[[:space: ]]*\(iface\ |auto\| mapping\ |source\ |allow- \) ! s/^/#NetworkMan ager#// ; }" /etc/network/ interfaces
(Can probably be done more elegantly with awk than with sed)