1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-25 22:27:42 +00:00

Declare and assign separately to avoid masking return values.

ShellCheck SC2155
This commit is contained in:
William Melody 2015-09-11 19:43:56 -07:00
parent 5759ade2eb
commit 12d11c2dc3

21
hosts
View File

@ -679,7 +679,8 @@ add() {
else else
if [[ -n ${comment} ]] if [[ -n ${comment} ]]
then then
local formatted_comment=$(_join " " "${comment[@]}") local formatted_comment
formatted_comment=$(_join " " "${comment[@]}")
printf "%s\t%s\t# %s\n" \ printf "%s\t%s\t# %s\n" \
"${ip}" \ "${ip}" \
"${hostname}" \ "${hostname}" \
@ -712,7 +713,8 @@ disable() {
else else
_debug printf "disable() \$search_term: %s\n" "$search_term" _debug printf "disable() \$search_term: %s\n" "$search_term"
local targets=$( local targets
targets=$(
sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}" sed -n "s/^\([^#]*${search_term}.*\)$/\1/p" "${HOSTS_PATH}"
) )
_debug printf "disable() \$targets: %s\n" "$targets" _debug printf "disable() \$targets: %s\n" "$targets"
@ -777,7 +779,8 @@ enable() {
else else
local target_regex="s/^\#disabled: \(.*${search_term}.*\)$/\1/" local target_regex="s/^\#disabled: \(.*${search_term}.*\)$/\1/"
local targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}") local targets
targets=$(sed -n "${target_regex}p" "${HOSTS_PATH}")
printf "Enabling:\n%s\n" "${targets}" printf "Enabling:\n%s\n" "${targets}"
# -i '' - in place edit. BSD sed requires extension argument, for GNU # -i '' - in place edit. BSD sed requires extension argument, for GNU
@ -825,7 +828,8 @@ Description:
EOM EOM
list() { list() {
# Get the disabled records up front for the two cases where they are needed. # Get the disabled records up front for the two cases where they are needed.
local disabled_records=$( local disabled_records
disabled_records=$(
sed -n "s/^\#disabled: \(.*\)$/\1/p" "${HOSTS_PATH}" sed -n "s/^\#disabled: \(.*\)$/\1/p" "${HOSTS_PATH}"
) )
@ -872,7 +876,8 @@ remove() {
$_ME help remove $_ME help remove
exit 1 exit 1
else else
local target_records=$( local target_records
target_records=$(
sed -n "s/^\(.*${search_string}.*\)$/\1/p" "${HOSTS_PATH}" sed -n "s/^\(.*${search_string}.*\)$/\1/p" "${HOSTS_PATH}"
) )
@ -921,10 +926,12 @@ show() {
if [[ -n "$1" ]] if [[ -n "$1" ]]
then then
# Run `sed` before `grep` to avoid conflict that supress `sed` output. # Run `sed` before `grep` to avoid conflict that supress `sed` output.
local disabled_records=$( local disabled_records
disabled_records=$(
sed -n "s/^\#\(disabled: .*$1.*\)$/\1/p" "${HOSTS_PATH}" sed -n "s/^\#\(disabled: .*$1.*\)$/\1/p" "${HOSTS_PATH}"
) )
local enabled_records=$( local enabled_records
enabled_records=$(
grep "^[^#]*$1" "${HOSTS_PATH}" grep "^[^#]*$1" "${HOSTS_PATH}"
) )
# Output disabled records secondly for better organization. # Output disabled records secondly for better organization.