From 326fb75a856018ff102961a9759a09ac2fb10a28 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 9 Oct 2011 13:18:29 +0200 Subject: [PATCH] gsu: Avoid parameter expansion on unset variables. This patch allows to run scripts which use gsu with bash's -u option enabled. This is mostly useful to spot bugs due to typos in variable names. --- misc/gsu/config | 4 ++-- misc/gsu/subcommand | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/misc/gsu/config b/misc/gsu/config index e8d4471..ff77dae 100644 --- a/misc/gsu/config +++ b/misc/gsu/config @@ -8,7 +8,7 @@ gsu_check_options() for ((i=0; i < ${#gsu_options[@]}; i++)); do eval "${gsu_options[$i]}" - eval val='"'\$$name'"' + eval val='"'\${${name}:-}'"' eval orig_${gsu_config_var_prefix}_$name='"'${val}'"' done @@ -33,7 +33,7 @@ gsu_check_options() eval orig_val='"'\$orig_${gsu_config_var_prefix}_$name'"' if [[ -z "$orig_val" ]]; then - eval val='"'\$$name'"' + eval val='"'\${$name:-}'"' else val="$orig_val" fi diff --git a/misc/gsu/subcommand b/misc/gsu/subcommand index a688ed5..e1130ef 100644 --- a/misc/gsu/subcommand +++ b/misc/gsu/subcommand @@ -42,7 +42,7 @@ _gsu_available_commands() _gsu_print_available_commands() {( - local i count + local i count=0 gsu_short_msg "Available commands:" for i in $gsu_cmds; do printf "$i" @@ -216,7 +216,7 @@ _com_help() _gsu_get_command_regex ere="$result" - if test -z "$1"; then + if (($# == 0)); then _gsu_banner_msg 2>&1 _gsu_usage 2>&1 { @@ -355,11 +355,11 @@ gsu_getopts() for ((i=0; i < ${#1}; i++)); do c1=${1:$i:1} c2=${1:$(($i + 1)):1} - result+=" o_$c1" + result+=" o_$c1=" if [[ "$c2" = ":" ]]; then let i++ else - result+="=false" + result+="false" fi done result+=" -- 2.39.5