From 975bf63eb5e5e96c101d5c1d39effe0ea15dc16c Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Jun 01 2021 07:01:14 +0000 Subject: Shellcheckify sysusers.generate-pre.sh There should be almost no functional change, but shellcheck complains less. User/group descriptions with escaped characters are handled properly. --- diff --git a/sysusers.generate-pre.sh b/sysusers.generate-pre.sh index 9441971..fd9938d 100755 --- a/sysusers.generate-pre.sh +++ b/sysusers.generate-pre.sh @@ -13,10 +13,10 @@ user() { shell="$6" [ "$desc" = '-' ] && desc= - [ "$home" = '-' -o "$home" = '' ] && home=/ - [ "$shell" = '-' -o "$shell" = '' ] && shell=/sbin/nologin + { [ "$home" = '-' ] || [ "$home" = '' ]; } && home=/ + { [ "$shell" = '-' ] || [ "$shell" = '' ]; } && shell=/sbin/nologin - if [ "$uid" = '-' -o "$uid" = '' ]; then + if [ "$uid" = '-' ] || [ "$uid" = '' ]; then cat </dev/null || \\ useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user' @@ -50,11 +50,11 @@ group() { } parse() { - while read line || [ "$line" ]; do - [ "${line:0:1}" = '#' -o "${line:0:1}" = ';' ] && continue + while read -r line || [ -n "$line" ] ; do + { [ "${line:0:1}" = '#' ] || [ "${line:0:1}" = ';' ]; } && continue line="${line## *}" [ -z "$line" ] && continue - eval arr=( $line ) + eval "arr=( $line )" case "${arr[0]}" in ('u') group "${arr[1]}" "${arr[2]}" @@ -74,6 +74,6 @@ parse() { for fn in "$@"; do [ -e "$fn" ] || continue - echo "# generated from $(basename $fn)" + echo "# generated from $(basename "$fn")" parse <"$fn" done