1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-26 06:46:43 +00:00

Declare and assign separately to avoid masking return values.

ShellCheck SC2155

https://github.com/koalaman/shellcheck/wiki/SC2155
This commit is contained in:
William Melody 2015-04-18 21:17:46 -07:00
parent cb9e20e554
commit 2c83de9dff

12
hosts
View File

@ -280,7 +280,8 @@ _load_commands() {
do do
# Each element has the format `declare -f function_name`, so set the name # Each element has the format `declare -f function_name`, so set the name
# to only the 'function_name' part of the string. # to only the 'function_name' part of the string.
local function_name=$(printf "%s" "$c" | awk '{ print $3 }') local function_name
function_name=$(printf "%s" "$c" | awk '{ print $3 }')
_debug printf "_load_commands() \$function_name: %s\n" "$function_name" _debug printf "_load_commands() \$function_name: %s\n" "$function_name"
@ -376,7 +377,8 @@ _contains() {
_join() { _join() {
local separator="$1" local separator="$1"
local target_array=(${@:2}) local target_array=(${@:2})
local dirty="$(printf "${separator}%s" "${target_array[@]}")" local dirty
dirty="$(printf "${separator}%s" "${target_array[@]}")"
local clean="${dirty:${#separator}}" local clean="${dirty:${#separator}}"
printf "%s" "${clean}" printf "%s" "${clean}"
} }
@ -614,7 +616,8 @@ add() {
"${HOSTS_PATH}" "${HOSTS_PATH}"
else else
if [[ -n ${comment} ]]; then if [[ -n ${comment} ]]; then
local formmatted_comment=$(_join " " "${comment[@]}") local formmatted_comment
formmatted_comment=$(_join " " "${comment[@]}")
printf "%s\t%s\t# %s\n" \ printf "%s\t%s\t# %s\n" \
"${ip}" \ "${ip}" \
"${hostname}" \ "${hostname}" \
@ -788,7 +791,8 @@ remove() {
$_ME help remove $_ME help remove
exit 1 exit 1
else else
local target_records=$(sed -n "s/^\(.*${search_string}.*\)$/\1/p" "${HOSTS_PATH}") local target_records
target_records=$(sed -n "s/^\(.*${search_string}.*\)$/\1/p" "${HOSTS_PATH}")
if [[ -z ${target_records:-} ]]; then if [[ -z ${target_records:-} ]]; then
printf "No matching records found.\n" printf "No matching records found.\n"
exit 1 exit 1