mirror of
https://github.com/octoleo/hosts.git
synced 2024-11-22 21:05:11 +00:00
Add optional extension argument to sed -i
calls
BSD sed requires the optional exention argument for the -i option, while in GNU sed it's optional. Including a blank extension for portability.
This commit is contained in:
parent
13d1428ee9
commit
02a87b0938
15
hosts
15
hosts
@ -647,11 +647,16 @@ disable() {
|
|||||||
$_ME help disable
|
$_ME help disable
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
_debug printf "disable() \$search_term: %s\n" "$search_term"
|
||||||
|
|
||||||
targets=$(sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}")
|
targets=$(sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}")
|
||||||
|
_debug printf "disable() \$targets: %s\n" "$targets"
|
||||||
|
|
||||||
printf "Disabling:\n%s\n" "${targets}"
|
printf "Disabling:\n%s\n" "${targets}"
|
||||||
|
|
||||||
sed -i "s/^\([^#]*${search_term}.*\)$/\#disabled: \1/g" "${HOSTS_PATH}"
|
# -i '' - in place edit. BSD sed requires extension argument, for GNU
|
||||||
|
# it's optional. More info: http://stackoverflow.com/a/16746032
|
||||||
|
sed -i '' "s/^\([^#]*${search_term}.*\)$/\#disabled: \1/g" "${HOSTS_PATH}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,7 +713,9 @@ enable() {
|
|||||||
targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}")
|
targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}")
|
||||||
printf "Enabling:\n%s\n" "${targets}"
|
printf "Enabling:\n%s\n" "${targets}"
|
||||||
|
|
||||||
sed -i "${target_regex}g" "${HOSTS_PATH}"
|
# -i '' - in place edit. BSD sed requires extension argument, for GNU
|
||||||
|
# it's optional. More info: http://stackoverflow.com/a/16746032
|
||||||
|
sed -i '' "${target_regex}g" "${HOSTS_PATH}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -815,7 +822,9 @@ remove() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
sed -i "/^.*${search_string}.*$/d" "${HOSTS_PATH}"
|
# -i '' - in place edit. BSD sed requires extension argument, for GNU
|
||||||
|
# it's optional. More info: http://stackoverflow.com/a/16746032
|
||||||
|
sed -i '' "/^.*${search_string}.*$/d" "${HOSTS_PATH}"
|
||||||
printf "Removed:\n%s\n" "${target_records}"
|
printf "Removed:\n%s\n" "${target_records}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user