AlainD
AlainD

Reputation: 6607

How to make bashdb and VS Code's Debugger use the same environment and functions from the user .bashrc?

I'm using Visual Studio Code 1.39.2 on Ubuntu 18.04 to debug a bash script.

In my environment .bashrc file, I have defined a function hello1:

function hello1
{
    echo Hello from .bashrc!
}

In my bash script, I've added another function hello2:

function hello2
{
    echo Hello from your script!
}

and the script contains the lines:

hello1
hello2

Now set the following launch configuration:

{
    "type": "bashdb",
    "request": "launch",
    "name": "Debug: Active script",
    "program": "${file}"
}

Before debugging, enter the Terminal window within VS code. Type hello1 and the output is Hello from .bashrc!. Then type hello2 and as expected, Command 'hello2' not found is the result because this function is not known to the bash shell. All good.

Now debug from within VS Code (choose the Debug: Active script configuration with the script active). Watch the Debug Console window as you step through the script. This time hello2 works but you get an error for hello1:

line X: hello1: command not found

How do you make bashdb and the Debug Console window understand environment and functions from the user .bashrc?

Upvotes: 1

Views: 899

Answers (1)

Gino Mempin
Gino Mempin

Reputation: 29608

It works when you export the function:

function hello1
{
  echo Hello from bashrc
}
export -f hello1

enter image description here

Upvotes: 1

Related Questions