vscode-bash-debug icon indicating copy to clipboard operation
vscode-bash-debug copied to clipboard

How to debug and trace into several bash files

Open Starli0n opened this issue 4 years ago • 3 comments

Hi,

First thank you for your awesome plugin 👋

I would like to know if it is possible to debug in several files.

For instance, I manage perfectly to debug a sh file but at some I would like to step in (F11) another sh file. I have a sh file that is calling another one. But the later, it seems I cannot trace into it.

I do not know if it is even possible as I even tried to call the secondary script with its full path and put breakpoints there, without success. If yes, could you please tell me how please ?

Thank you

Starli0n avatar Apr 07 '21 19:04 Starli0n

It is possible, when you use bash "source" keyword, or simply "."

https://superuser.com/questions/46139/what-does-source-do

rogalmic avatar Apr 09 '21 06:04 rogalmic

This solution enables to step in other scripts, thanks.

However it changes the behavior. For instance, let's say that I set a variable at the beginning of each script like:

SCRIPT_NAME=$(basename $0)

all my sourced scripts would have the value of the main script calling them instead of their own value.

Is there a workaround to this ?

Starli0n avatar Apr 15 '21 19:04 Starli0n

There is no workaround, since separate bash process is created when you execute script instead of calling it via source.

rogalmic avatar Apr 15 '21 21:04 rogalmic