From 97e89acc94d946d32a316c12dfbea0a1fd520346 Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Thu, 14 Dec 2023 12:37:45 +0100 Subject: [PATCH] Fix pollution with global variables by getopts_long --- bashdb-part2.sh | 1 + command/backtrace.sh | 4 +++- command/shell.sh | 4 +++- init/opts.sh | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bashdb-part2.sh b/bashdb-part2.sh index 3889bc40..2e052886 100644 --- a/bashdb-part2.sh +++ b/bashdb-part2.sh @@ -30,6 +30,7 @@ # I don't know why when this is done in dbg-opts.sh it doesn't have # an effect. ((OPTLIND > 0)) && shift "$((OPTLIND - 1))" +unset OPTLIND if (($# == 0)) && [[ -z "$_Dbg_EXECUTION_STRING" ]] ; then echo >&2 "${_Dbg_pname}: need to give a script to debug or use the -c option." diff --git a/command/backtrace.sh b/command/backtrace.sh index 54a6c415..69c933ee 100644 --- a/command/backtrace.sh +++ b/command/backtrace.sh @@ -74,7 +74,9 @@ function _Dbg_do_backtrace { _Dbg_not_running && return 3 typeset -i show_source=0 - OPTLIND='' + typeset -i OPTLIND=1 + typeset OPTLARG OPTLERR OPTLPENDING opt + while getopts_long sh opt \ source no_argument \ help no_argument \ diff --git a/command/shell.sh b/command/shell.sh index e0c4dd48..cd49556d 100644 --- a/command/shell.sh +++ b/command/shell.sh @@ -62,7 +62,9 @@ in the trap EXIT of the shell. " _Dbg_parse_shell_cmd_options() { - OPTLIND='' + typeset -i OPTLIND=1 + typeset OPTLARG OPTLERR OPTLPENDING opt + while getopts_long lFV opt \ no-fns 0 \ posix no_argument \ diff --git a/init/opts.sh b/init/opts.sh index d324aad4..4b6f12af 100644 --- a/init/opts.sh +++ b/init/opts.sh @@ -131,6 +131,7 @@ _Dbg_parse_options() { typeset -i _Dbg_o_quiet=0 typeset -i _Dbg_o_version=0 typeset -i _Dbg_highlight_enabled=1 + typeset OPTLARG OPTLERR OPTLPENDING opt while getopts_long A:Bc:x:hL:nqTt:Yy:VX opt \ annotate required_argument \