From 5a1e6ca8db85662ec3267400192742b00916b97a Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Wed, 9 Oct 2024 16:25:53 +0200 Subject: [PATCH 1/4] Don't pollute global variables with "fullname" Also wraps the assigned value in quotes for better whitespace handling --- lib/filecache.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/filecache.sh b/lib/filecache.sh index 9e88fd52..3ee92a9f 100644 --- a/lib/filecache.sh +++ b/lib/filecache.sh @@ -204,7 +204,8 @@ function _Dbg_readin { if [[ -z "$filename" ]] || [[ "$filename" == "$_Dbg_bogus_file" ]] ; then eval "${_Dbg_source_array_var}[0]=\"$Dbg_EXECUTION_STRING\"" else - fullname=$(_Dbg_resolve_expand_filename "$filename") + typeset fullname + fullname="$(_Dbg_resolve_expand_filename "$filename")" if [[ -r "$fullname" ]] ; then typeset -r progress_prefix="Reading $filename" _Dbg_file2canonic["$filename"]="$fullname" From 536585a03d682bbcf179b8bd3848b7bfc03f1b1f Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Wed, 9 Oct 2024 16:31:30 +0200 Subject: [PATCH 2/4] Don't pollute global variables with "opt" --- command/info_sub/variables.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/command/info_sub/variables.sh b/command/info_sub/variables.sh index fe48fccd..099e7e60 100644 --- a/command/info_sub/variables.sh +++ b/command/info_sub/variables.sh @@ -142,6 +142,7 @@ function _Dbg_info_variables_parse_options { typeset -i _Dbg_rc=0 typeset OPTLIND='' + typeset opt while getopts_long irxaAtp opt \ integer no_argument \ readonly no_argument \ From 2a1cd2bd583cc9f93d45a9eb7a2f40eecc9d7fc0 Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Wed, 9 Oct 2024 16:52:11 +0200 Subject: [PATCH 3/4] Don't pollute global variables with "prefix" Function declaration and call are on a single line because the line number is referenced by tests --- bashdb-main.inc.in | 4 ++-- bashdb.in | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bashdb-main.inc.in b/bashdb-main.inc.in index c4dbd70c..5c411bfa 100644 --- a/bashdb-main.inc.in +++ b/bashdb-main.inc.in @@ -38,8 +38,8 @@ typeset _Dbg_orig_0=$0 typeset _Dbg_pname=${0##*/} ## Stuff set by autoconf/configure ### -typeset prefix=@prefix@ # @PKGDATADIR@ often uses $prefix -typeset _Dbg_libdir=@PKGDATADIR@ +# @PKGDATADIR@ often uses $prefix, _Dbg_libdir must be a global variable +_Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; }; _Dbg_assign_libdir ### # We agonize a bit over _Dbg_libdir: the root directory for where diff --git a/bashdb.in b/bashdb.in index ca709a35..cc7a9aa9 100755 --- a/bashdb.in +++ b/bashdb.in @@ -49,8 +49,8 @@ typeset _Dbg_orig_0=$0 typeset _Dbg_pname=${0##*/} ## Stuff set by autoconf/configure ### -typeset prefix=@prefix@ # @PKGDATADIR@ often uses $prefix -typeset _Dbg_libdir="@PKGDATADIR@" +# @PKGDATADIR@ often uses $prefix, _Dbg_libdir must be a global variable +_Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; }; _Dbg_assign_libdir ### # We agonize a bit over _Dbg_libdir: the root directory for where From 6fe938e01bf334dc99c3946ad4d7d8142efe9d1f Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Wed, 9 Oct 2024 16:53:43 +0200 Subject: [PATCH 4/4] Better handling of spaces in paths --- bashdb-main.inc.in | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bashdb-main.inc.in b/bashdb-main.inc.in index 5c411bfa..954588fd 100644 --- a/bashdb-main.inc.in +++ b/bashdb-main.inc.in @@ -29,13 +29,13 @@ typeset _Dbg_release='@PACKAGE_VERSION@' typeset _Dbg_bashdb_main='@DBGR_MAIN@' # The short shell name. Helps keep code common in bash, zsh, and ksh debuggers. -typeset _Dbg_shell_name=${_Dbg_shell##*/} # Equivalent to basename(_Dbg_shell) +typeset _Dbg_shell_name="${_Dbg_shell##*/}" # Equivalent to basename(_Dbg_shell) # Original $0. Note we can't set this in an include. -typeset _Dbg_orig_0=$0 +typeset _Dbg_orig_0="$0" # Equivalent to basename $0; the short program name -typeset _Dbg_pname=${0##*/} +typeset _Dbg_pname="${0##*/}" ## Stuff set by autoconf/configure ### # @PKGDATADIR@ often uses $prefix, _Dbg_libdir must be a global variable @@ -44,11 +44,11 @@ _Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; }; # We agonize a bit over _Dbg_libdir: the root directory for where # debugger code is stored. -[[ -d $_Dbg_libdir ]] || _Dbg_libdir=${_Dbg_bashdb_main%/*} # dirname(_Dbg_bashdb_main) -[[ -d $_Dbg_libdir ]] || _Dbg_libdir='.' +[[ -d "$_Dbg_libdir" ]] || _Dbg_libdir="${_Dbg_bashdb_main%/*}" # dirname(_Dbg_bashdb_main) +[[ -d "$_Dbg_libdir" ]] || _Dbg_libdir='.' typeset _Dbg_main="$_Dbg_libdir/dbg-main.sh" -if [[ ! -r $_Dbg_main ]] ; then +if [[ ! -r "$_Dbg_main" ]] ; then echo "${_Dbg_pname}: Can't read debugger library file '${_Dbg_main}'." echo "${_Dbg_pname}: Perhaps @PACKAGE@ is installed wrong (if its installed)." >&2 echo "${_Dbg_pname}: Try running @PACKAGE@ using -L (with a different directory)." >&2 @@ -57,6 +57,6 @@ if [[ ! -r $_Dbg_main ]] ; then fi # Pull in the rest of the debugger code. -. $_Dbg_main +. "$_Dbg_main" trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG