Debugger does not honor positional parameters

We are trying out the debugger. Mostly it is very impressive!

One problem we are struggling with is positional parameters. BASH conventions are $0 is the path to the script itself. So if you launch a script: /my/bin/ then $0 is /my/bin/ and:

echo $( basename "$0" ) 

produces the output: “”

When you launch with the debugger, $0 is the path to the debugger script and $1 is the path to /my/bin/, breaking any BASH that does path mapping.

Can you launch the debugger in such a way that it properly manages positional parameters?


Hi @jay.guidos, thanks for reporting!

This is currently a limitation, because bashdb (the debugger) is a script by itself. I’ll look into this again if there’s a way to circumvent this. I’m tracking this at .

Are you debgugging with Bash 4 or Bash 5 ?


Update: debugging with Bash 5 should already fix the value of $0 via BASH_ARGV0, which is a new feature in Bash 5.

Debugging with Bash 4 can not update the value of $0.

Thanks Joachim,

We are on Bash 4.

I skimmed through the bashdb user manual and it seems there may be a launch option to handle this situation:

One problem with sourcing a debugged script is that the program name stored in $0 will be bashdb rather than the name of the script to be debugged. The debugged script will appear in a call stack not as the top item but as the item below bashdb. If this is of concern, use the last form given above, bash --debugger script-name [script-options].

If you launch this way it should work ok to what we are looking for, yes?

Regards, Jay

Hi @jay.guidos,
you’re right bash --debugger script.bash is another way to launch the debugger.

Unfortunately it’s not possible to use it with the plugin, because bash locates and launches bashdb at a path, which is defined at compile-time, i.e. the path is in the bash binary. It’s not possible to override this path at runtime.

BashSupport Pro bundles bashdb for Bash 4 and for Bash 5. The bundled versions are slightly modified to support the debugger integration. And relying an an unknown, system-wide version of bashdb would create different problems.

Possible workaround:
I’ve tested with Bash 4. I’m only seeing the different value of $0, but not of the args $1, $2, etc.

You may want to use ${BASH_SOURCE[0]} or ${_Dbg_script_file:-$0} instead of $0 to make this work when it’s used in the debugger. _Dbg_script_file is defined by bashdb and points to the debugged file. I haven’t tested this for sourced files.

Possible fix:
I found out that bashdb has a set0 command, which can be used as a built-in to override the value of $0. This is C code and I’d have to build this against all supported versions of Bash on all of Linux, macOS and Windows, bundle it and find a way to integrate it with the debugged program.

I can’t promise yet that this will work, but I’ll try.