on master help sign in
shellcheck: fix usse -n instead of ! -z (SC2236 SC2237)

- https://www.shellcheck.net/wiki/SC2236 -- Use -n instead of ! -z. - https://www.shellcheck.net/wiki/SC2237 -- Use [ -n .. ] instead of ! [ -z .... Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commitad3273986024c80cfe067d1b77983901a41b6d01 authorMarkus Heiser <markus.heiser@darmarit.de> dateSun 16 Feb 2020, 20:07 (7 years ago) parente8cf225
5 files changed+26−23
utils/filtron.sh+1−1 utils/lib.sh+17−17 utils/lxc.sh+6−3 utils/morty.sh+1−1 utils/searx.sh+1−1
utils/filtron.sh+1−1
@@ -97,7 +97,7 @@ If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"
9797 FILTRON_TARGET : ${FILTRON_TARGET}
9898
9999EOF
100− [ ! -z "${1+x}" ] && err_msg "$1"
100+ [[ -n ${1} ]] && err_msg "$1"
101101}
102102
103103main() {
utils/lib.sh+17−17
@@ -57,7 +57,7 @@ required_commands() {
5757 # usage: requires_commands [cmd1 ...]
5858
5959 local exit_val=0
60− while [ ! -z "$1" ]; do
60+ while [ -n "$1" ]; do
6161
6262 if ! command -v "$1" &>/dev/null; then
6363 err_msg "missing command $1"
@@ -125,7 +125,7 @@ rst_title() {
125125rst_para() {
126126 # usage: RST_INDENT=1 rst_para "lorem ipsum ..."
127127 local prefix=''
128− if ! [[ -z $RST_INDENT ]] && [[ $RST_INDENT -gt 0 ]]; then
128+ if [[ -n $RST_INDENT ]] && [[ $RST_INDENT -gt 0 ]]; then
129129 prefix="$(for i in $(seq 1 "$RST_INDENT"); do printf " "; done)"
130130 echo -en "\n$*\n" | $FMT | prefix_stdout "$prefix"
131131 else
@@ -151,8 +151,8 @@ wait_key(){
151151 local msg="${MSG}"
152152 [[ -z "$msg" ]] && msg="${_Green}** press any [${_BCyan}KEY${_Green}] to continue **${_creset}"
153153
154− [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
155− [[ ! -z $_t ]] && _t="-t $_t"
154+ [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
155+ [[ -n $_t ]] && _t="-t $_t"
156156 printf "$msg"
157157 # shellcheck disable=SC2086
158158 read -r -s -n1 $_t
@@ -167,8 +167,8 @@ ask_yn() {
167167 local EXIT_NO=1 # exit status 1 --> error code
168168
169169 local _t=$3
170− [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
171− [[ ! -z $_t ]] && _t="-t $_t"
170+ [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
171+ [[ -n $_t ]] && _t="-t $_t"
172172 case "${FORCE_SELECTION:-${2}}" in
173173 Y) return ${EXIT_YES} ;;
174174 N) return ${EXIT_NO} ;;
@@ -218,7 +218,7 @@ tee_stderr () {
218218 # hello
219219
220220 local _t="0";
221− if [[ ! -z $1 ]] ; then _t="$1"; fi
221+ if [[ -n $1 ]] ; then _t="$1"; fi
222222
223223 (while read -r line; do
224224 # shellcheck disable=SC2086
@@ -233,7 +233,7 @@ prefix_stdout () {
233233
234234 local prefix="${_BYellow}-->|${_creset}"
235235
236− if [[ ! -z $1 ]] ; then prefix="${_BYellow}$1${_creset}"; fi
236+ if [[ -n $1 ]] ; then prefix="${_BYellow}$1${_creset}"; fi
237237
238238 # shellcheck disable=SC2162
239239 (while IFS= read line; do
@@ -260,7 +260,7 @@ cache_download() {
260260
261261 local exit_value=0
262262
263− if [[ ! -z ${SUDO_USER} ]]; then
263+ if [[ -n ${SUDO_USER} ]]; then
264264 sudo -u "${SUDO_USER}" mkdir -p "${CACHE}"
265265 else
266266 mkdir -p "${CACHE}"
@@ -274,7 +274,7 @@ cache_download() {
274274 if [[ ! -f "${CACHE}/$2" ]]; then
275275 info_msg "caching: $1"
276276 info_msg " --> ${CACHE}/$2"
277− if [[ ! -z ${SUDO_USER} ]]; then
277+ if [[ -n ${SUDO_USER} ]]; then
278278 sudo -u "${SUDO_USER}" wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
279279 else
280280 wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
@@ -298,8 +298,8 @@ choose_one() {
298298 local choice=$1;
299299 local max="${#@}"
300300 local _t
301− [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
302− [[ ! -z $_t ]] && _t="-t $_t"
301+ [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
302+ [[ -n $_t ]] && _t="-t $_t"
303303
304304 list=("$@")
305305 echo -e "${_BGreen}Menu::${_creset}"
@@ -374,7 +374,7 @@ install_template() {
374374 local chmod="${pos_args[4]-644}"
375375
376376 info_msg "install (eval=$do_eval): ${dst}"
377− [[ ! -z $variant ]] && info_msg "variant: ${variant}"
377+ [[ -n $variant ]] && info_msg "variant: ${variant}"
378378
379379 if [[ ! -f "${template_origin}" ]] ; then
380380 err_msg "${template_origin} does not exists"
@@ -386,14 +386,14 @@ install_template() {
386386 if [[ "$do_eval" == "1" ]]; then
387387 template_file="${CACHE}${dst}${variant}"
388388 info_msg "BUILD template ${template_file}"
389− if [[ ! -z ${SUDO_USER} ]]; then
389+ if [[ -n ${SUDO_USER} ]]; then
390390 sudo -u "${SUDO_USER}" mkdir -p "$(dirname "${template_file}")"
391391 else
392392 mkdir -p "$(dirname "${template_file}")"
393393 fi
394394 # shellcheck disable=SC2086
395395 eval "echo \"$(cat ${template_origin})\"" > "${template_file}"
396− if [[ ! -z ${SUDO_USER} ]]; then
396+ if [[ -n ${SUDO_USER} ]]; then
397397 chown "${SUDO_USER}:${SUDO_USER}" "${template_file}"
398398 fi
399399 else
@@ -856,8 +856,8 @@ git_clone() {
856856 fi
857857
858858 [[ -z $branch ]] && branch=master
859− [[ -z $user ]] && [[ ! -z "${SUDO_USER}" ]] && user="${SUDO_USER}"
860− [[ ! -z $user ]] && bash_cmd="sudo -H -u $user -i"
859+ [[ -z $user ]] && [[ -n "${SUDO_USER}" ]] && user="${SUDO_USER}"
860+ [[ -n $user ]] && bash_cmd="sudo -H -u $user -i"
861861
862862 if [[ -d "${dest}" ]] ; then
863863 info_msg "already cloned: $dest"
utils/lxc.sh+6−3
@@ -31,6 +31,7 @@ ubu1804_boilerplate="
3131export DEBIAN_FRONTEND=noninteractive
3232apt-get install -y git curl wget
3333"
34+# shellcheck disable=SC2034
3435ubu1904_boilerplate="$ubu1804_boilerplate"
3536
3637REMOTE_IMAGES=()
@@ -75,7 +76,7 @@ all LXC containers:
7576 ${LOCAL_IMAGES[@]}
7677
7778EOF
78− [ ! -z "${1+x}" ] && err_msg "$1"
79+ [ -n "${1+x}" ] && err_msg "$1"
7980}
8081
8182lxd_info() {
@@ -255,7 +256,7 @@ lxc_boilerplate_containers() {
255256 lxc start -q "${HOST_PREFIX}-${shortname}" &>/dev/null
256257 boilerplate_script="${shortname}_boilerplate"
257258 boilerplate_script="${!boilerplate_script}"
258− if [[ ! -z "${boilerplate_script}" ]]; then
259+ if [[ -n "${boilerplate_script}" ]]; then
259260 echo "$boilerplate_script" \
260261 | lxc exec "${HOST_PREFIX}-${shortname}" -- bash \
261262 | prefix_stdout " ${HOST_PREFIX}-${shortname} | "
@@ -305,11 +306,13 @@ add_subordinate_ids() {
305306
306307del_subordinate_ids() {
307308 local out
309+ local exit_value
308310 if grep "root:${HOST_USER_ID}:1" /etc/subuid -qs; then
309311 # TODO: root user is always in use by process 1, how can we remove subordinates?
310312 info_msg "remove lxd permission to map ${HOST_USER_ID}'s user/group id through"
311313 out=$(usermod --del-subuids "${HOST_USER_ID}-${HOST_USER_ID}" --del-subgids "${HOST_GROUP_ID}-${HOST_GROUP_ID}" root 2>&1)
312− if [ ! -z $? ]; then
314+ exit_val=$?
315+ if [ $exit_val -ne 0 ]; then
313316 err_msg "$out"
314317 fi
315318 else
utils/morty.sh+1−1
@@ -84,7 +84,7 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file::
8484 SERVICE_USER : ${SERVICE_USER}
8585EOF
8686 info_searx
87− [ ! -z "${1+x}" ] && err_msg "$1"
87+ [[ -n ${1} ]] && err_msg "$1"
8888}
8989
9090info_searx() {
utils/searx.sh+1−1
@@ -110,7 +110,7 @@ If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"
110110 SERVICE_USER : ${SERVICE_USER}
111111
112112EOF
113− [ ! -z "${1+x}" ] && err_msg "$1"
113+ [[ -n ${1} ]] && err_msg "$1"
114114}
115115
116116main() {