From c4994258695f2875fe75ea3c499df85cf87fe5bf Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Tue, 29 Oct 2013 19:29:59 -0400 Subject: [PATCH] Fixed the exporting of cmdarg_ and CMDARG_ variables for subshells (for real this time) --- cmdarg.sh | 56 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/cmdarg.sh b/cmdarg.sh index 27da263..3de5b39 100644 --- a/cmdarg.sh +++ b/cmdarg.sh @@ -324,35 +324,39 @@ function cmdarg_purge arrays="$arrays CMDARG_FLAGS CMDARG_TYPES" for arr in $arrays do - unset $arr - unset $arr[*] + str='${!'"$arr"'[@]}' + for key in $(eval "echo $str") + do + str="$arr[$key]" + eval "unset $str" + done done CMDARG_GETOPTLIST="h" } -# Holds the final map of configuration options -declare -A cmdarg_cfg -# Maps (short arg) -> (long arg) -declare -A CMDARG -# Maps (long arg) -> (short arg) -declare -A CMDARG_REV -# A list of optional arguments (e.g., no :) -declare -a CMDARG_OPTIONAL -# A list of required arguments (e.g., :) -declare -a CMDARG_REQUIRED -# Maps (short arg) -> (description) -declare -A CMDARG_DESC -# Maps (short arg) -> default -declare -A CMDARG_DEFAULT -# Maps (short arg) -> validator -declare -A CMDARG_VALIDATORS -# Miscellanious info about this script -declare -A CMDARG_INFO -# Map of (short arg) -> flags -declare -A CMDARG_FLAGS -# Map of (short arg) -> type (string, array, hash) -declare -A CMDARG_TYPES - -if [[ "${CMDARG_GETOPTLIST}" == "" ]]; then +if [[ "${_DEFINED_CMDARG}" == "" ]]; then + export _DEFINED_CMDARG=0 + # Holds the final map of configuration options + declare -A cmdarg_cfg + # Maps (short arg) -> (long arg) + declare -A CMDARG + # Maps (long arg) -> (short arg) + declare -A CMDARG_REV + # A list of optional arguments (e.g., no :) + declare -a CMDARG_OPTIONAL + # A list of required arguments (e.g., :) + declare -a CMDARG_REQUIRED + # Maps (short arg) -> (description) + declare -A CMDARG_DESC + # Maps (short arg) -> default + declare -A CMDARG_DEFAULT + # Maps (short arg) -> validator + declare -A CMDARG_VALIDATORS + # Miscellanious info about this script + declare -A CMDARG_INFO + # Map of (short arg) -> flags + declare -A CMDARG_FLAGS + # Map of (short arg) -> type (string, array, hash) + declare -A CMDARG_TYPES CMDARG_GETOPTLIST="h" fi