fix shellcheck errors

shellcheck 0.4.7 seems to have come up with new checks and now complains
about yet more possible issues. fixed them all as good as i could.
This commit is contained in:
Manuel Streuhofer
2018-01-21 23:02:03 +01:00
parent cf7d25e3d1
commit 236e3c7eca
7 changed files with 54 additions and 49 deletions

View File

@ -27,6 +27,7 @@
# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}. # - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}.
# you can use bash variables to work around this (so use ${HOME} instead) # you can use bash variables to work around this (so use ${HOME} instead)
# shellcheck disable=SC2034
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-f --file [arg] Filename to process. Required. -f --file [arg] Filename to process. Required.
-t --temp [arg] Location of tempfile. Default="/tmp/bar" -t --temp [arg] Location of tempfile. Default="/tmp/bar"
@ -37,6 +38,7 @@ read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-1 --one Do just one thing -1 --one Do just one thing
EOF EOF
# shellcheck disable=SC2034
read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered
This is Bash3 Boilerplate's help text. Feel free to add any description of your This is Bash3 Boilerplate's help text. Feel free to add any description of your
program or elaborate more on command-line arguments. This section is not program or elaborate more on command-line arguments. This section is not
@ -59,6 +61,7 @@ trap __b3bp_cleanup_before_exit EXIT
__b3bp_err_report() { __b3bp_err_report() {
local error_code local error_code
error_code=${?} error_code=${?}
# shellcheck disable=SC2154
error "Error in ${__file} in function ${1} on line ${2}" error "Error in ${__file} in function ${1} on line ${2}"
exit ${error_code} exit ${error_code}
} }
@ -104,9 +107,13 @@ fi
### Runtime ### Runtime
############################################################################## ##############################################################################
# shellcheck disable=SC2154
info "__i_am_main_script: ${__i_am_main_script}" info "__i_am_main_script: ${__i_am_main_script}"
# shellcheck disable=SC2154
info "__file: ${__file}" info "__file: ${__file}"
# shellcheck disable=SC2154
info "__dir: ${__dir}" info "__dir: ${__dir}"
# shellcheck disable=SC2154
info "__base: ${__base}" info "__base: ${__base}"
info "OSTYPE: ${OSTYPE}" info "OSTYPE: ${OSTYPE}"
@ -115,7 +122,7 @@ info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}" info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}" info "arg_h: ${arg_h}"
info "$(echo -e "multiple lines example - line #1\nmultiple lines example - line #2\nimagine logging the output of 'ls -al /path/'")" info "$(echo -e "multiple lines example - line #1\\nmultiple lines example - line #2\\nimagine logging the output of 'ls -al /path/'")"
# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software # All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software
debug "Info useful to developers for debugging the application, not useful during operations." debug "Info useful to developers for debugging the application, not useful during operations."

24
main.sh
View File

@ -62,26 +62,26 @@ function __b3bp_log () {
shift shift
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_debug="\x1b[35m" local color_debug="\\x1b[35m"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_info="\x1b[32m" local color_info="\\x1b[32m"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_notice="\x1b[34m" local color_notice="\\x1b[34m"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_warning="\x1b[33m" local color_warning="\\x1b[33m"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_error="\x1b[31m" local color_error="\\x1b[31m"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_critical="\x1b[1;31m" local color_critical="\\x1b[1;31m"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_alert="\x1b[1;33;41m" local color_alert="\\x1b[1;33;41m"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local color_emergency="\x1b[1;4;5;33;41m" local color_emergency="\\x1b[1;4;5;33;41m"
local colorvar="color_${log_level}" local colorvar="color_${log_level}"
local color="${!colorvar:-${color_error}}" local color="${!colorvar:-${color_error}}"
local color_reset="\x1b[0m" local color_reset="\\x1b[0m"
if [[ "${NO_COLOR:-}" = "true" ]] || ( [[ "${TERM:-}" != "xterm"* ]] && [[ "${TERM:-}" != "screen"* ]] ) || [[ ! -t 2 ]]; then if [[ "${NO_COLOR:-}" = "true" ]] || ( [[ "${TERM:-}" != "xterm"* ]] && [[ "${TERM:-}" != "screen"* ]] ) || [[ ! -t 2 ]]; then
if [[ "${NO_COLOR:-}" != "false" ]]; then if [[ "${NO_COLOR:-}" != "false" ]]; then
@ -190,7 +190,7 @@ while read -r __b3bp_tmp_line; do
[[ "${__b3bp_tmp_opt:-}" ]] || continue [[ "${__b3bp_tmp_opt:-}" ]] || continue
if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Default= ]]; then if [[ "${__b3bp_tmp_line}" =~ ^Default= ]] || [[ "${__b3bp_tmp_line}" =~ \.\ *Default= ]]; then
# ignore default value if option does not have an argument # ignore default value if option does not have an argument
__b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" __b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}"
@ -208,7 +208,7 @@ while read -r __b3bp_tmp_line; do
fi fi
fi fi
if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Required\. ]]; then if [[ "${__b3bp_tmp_line}" =~ ^Required\. ]] || [[ "${__b3bp_tmp_line}" =~ \.\ *Required\. ]]; then
# remember that this option requires an argument # remember that this option requires an argument
printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2" printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2"
fi fi
@ -380,7 +380,7 @@ info "arg_d: ${arg_d}"
info "arg_v: ${arg_v}" info "arg_v: ${arg_v}"
info "arg_h: ${arg_h}" info "arg_h: ${arg_h}"
info "$(echo -e "multiple lines example - line #1\nmultiple lines example - line #2\nimagine logging the output of 'ls -al /path/'")" info "$(echo -e "multiple lines example - line #1\\nmultiple lines example - line #2\\nimagine logging the output of 'ls -al /path/'")"
# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software # All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software
debug "Info useful to developers for debugging the application, not useful during operations." debug "Info useful to developers for debugging the application, not useful during operations."

View File

@ -57,7 +57,7 @@ function ini_val() {
echo "${key}${delim}${val}" >> "${file}" echo "${key}${delim}${val}" >> "${file}"
else else
# add to section # add to section
sed -i.bak -e "/\[${section}\]/a ${key}${delim}${val}" "${file}" sed -i.bak -e "/\\[${section}\\]/a ${key}${delim}${val}" "${file}"
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666 # this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
rm -f "${file}.bak" rm -f "${file}.bak"
fi fi

View File

@ -41,8 +41,8 @@ __accptstTmpDir=$(mktemp -d "${__sysTmpDir}/${__base}.XXXXXX")
function cleanup_before_exit () { rm -r "${__accptstTmpDir:?}"; } function cleanup_before_exit () { rm -r "${__accptstTmpDir:?}"; }
trap cleanup_before_exit EXIT trap cleanup_before_exit EXIT
cmdSed=sed cmdSed="sed"
cmdTimeout=timeout cmdTimeout="timeout"
if [[ "${OSTYPE}" = "darwin"* ]]; then if [[ "${OSTYPE}" = "darwin"* ]]; then
cmdSed=gsed cmdSed=gsed
@ -98,7 +98,7 @@ while IFS=$'\n' read -r scenario; do
-e "s@${USER:-travis}@{user}@g" "${curFile}" \ -e "s@${USER:-travis}@{user}@g" "${curFile}" \
-e "s@travis@{user}@g" "${curFile}" \ -e "s@travis@{user}@g" "${curFile}" \
-e "s@kvz@{user}@g" "${curFile}" \ -e "s@kvz@{user}@g" "${curFile}" \
-e "s@{root}/node_modules/\.bin/node@{node}@g" "${curFile}" \ -e "s@{root}/node_modules/\\.bin/node@{node}@g" "${curFile}" \
-e "s@{home}/build/{user}/fre{node}@{node}@g" "${curFile}" \ -e "s@{home}/build/{user}/fre{node}@{node}@g" "${curFile}" \
-e "s@${HOSTNAME}@{hostname}@g" "${curFile}" \ -e "s@${HOSTNAME}@{hostname}@g" "${curFile}" \
-e "s@${__arch}@{arch}@g" "${curFile}" \ -e "s@${__arch}@{arch}@g" "${curFile}" \
@ -177,10 +177,10 @@ while IFS=$'\n' read -r scenario; do
fi fi
if ! diff --strip-trailing-cr "${__dir}/fixture/${scenario}.${typ}" "${curFile}"; then if ! diff --strip-trailing-cr "${__dir}/fixture/${scenario}.${typ}" "${curFile}"; then
echo -e "\n\n==> MISMATCH OF: ${scenario}.${typ} ---^" echo -e "\\n\\n==> MISMATCH OF: ${scenario}.${typ} ---^"
echo -e "\n\n==> EXPECTED STDIO: " echo -e "\\n\\n==> EXPECTED STDIO: "
cat "${__dir}/fixture/${scenario}.stdio" || true cat "${__dir}/fixture/${scenario}.stdio" || true
echo -e "\n\n==> ACTUAL STDIO: " echo -e "\\n\\n==> ACTUAL STDIO: "
cat "${__accptstTmpDir}/${scenario}.stdio" || true cat "${__accptstTmpDir}/${scenario}.stdio" || true
exit 1 exit 1
fi fi
@ -195,8 +195,7 @@ done <<< "$(find "${__dir}/scenario" -type f -iname 'run.sh')"
# Ensure correct syntax with all available bashes # Ensure correct syntax with all available bashes
if bashes=($(which -a bash 2> /dev/null )); then while IFS=$'\n' read -r bash; do
for bash in "${bashes[@]}"; do
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo "==> ${bash} -n $(${bash} -c 'echo "(${BASH_VERSION})"')" echo "==> ${bash} -n $(${bash} -c 'echo "(${BASH_VERSION})"')"
pushd "${__root}" > /dev/null pushd "${__root}" > /dev/null
@ -224,8 +223,7 @@ if bashes=($(which -a bash 2> /dev/null )); then
cat "${__accptstTmpDir}/${bash//\//.}.err" cat "${__accptstTmpDir}/${bash//\//.}.err"
exit 1 exit 1
fi fi
done done <<< "$(which -a bash 2>/dev/null)"
fi
# do some shellcheck linting # do some shellcheck linting
if [[ "$(command -v shellcheck)" ]]; then if [[ "$(command -v shellcheck)" ]]; then

View File

@ -6,8 +6,6 @@ set -o nounset
# Set magic variables for current FILE & DIR # Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename "${__file}" .sh)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)" __root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
# echo "ACCPTST:STDIO_REPLACE_DATETIMES" # echo "ACCPTST:STDIO_REPLACE_DATETIMES"

View File

@ -22,6 +22,8 @@ read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
More description. More description.
EOF EOF
export __usage
echo "ACCPTST:STDIO_REPLACE_DATETIMES" echo "ACCPTST:STDIO_REPLACE_DATETIMES"
# shellcheck source=main.sh # shellcheck source=main.sh

View File

@ -42,7 +42,7 @@ for doc in "README" "FAQ" "CHANGELOG"; do
permalink="/${targetName}/" permalink="/${targetName}/"
subtitle="$(tr '[:lower:]' '[:upper:]' <<< "${targetName:0:1}")${targetName:1} | " subtitle="$(tr '[:lower:]' '[:upper:]' <<< "${targetName:0:1}")${targetName:1} | "
redirectFrom="/${doc}.md/" redirectFrom="/${doc}.md/"
backLink="\n\n<a href=\"/\">&laquo; Home</a>" backLink='\n\n<a href="/">&laquo; Home</a>'
if [[ "${doc}" = "README" ]]; then if [[ "${doc}" = "README" ]]; then
targetName="index" targetName="index"
permalink="/" permalink="/"