I have some shell scripts, which I would like to execute by name from code during debugging in Visual Studio Code. I need to extend $PATH environment variable to make it happened. Currently, I have following json in launch.json.
{
"name": "Debug-Linux",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"PATH": "$PATH:$(pwd)/../bin/"
},
"showLog": true
}
Also, I've tried
"env": {
"PATH": "${env.PATH}:$(pwd)/../bin/"
},
But, it does not work. How can I extend $PATH environment variable in launch.json in Visual Studio Code?
On Windows platform I found that Visual Studio Code seems to be case-sensitive. If the name of the variable is not spelled exactly as it is spelled on your machine, Visual Studio Code will ignore your variable from the launch.json.
For example, to properly set
path
environment variable when it is spelledPath
, you would need to add the following to launch.json.See Launch.json attributes and Variable Substitution in Visual Studio Code documentation for more information. Here what's mentioned there about the variable casing under Variable Substitution:
This is odd, because Windows is case-insensitive to the names of environment variables
I finally gave up on making that work, but the workaround I have done is to just paste the DOS command to set the path in the terminal before a debugging session. Something like:
A little bit ugly, but at least it lets me work. I add that as a comment to my launch.json so I have it readily available. Not completely sure that would transfer cleanly for your Linux environment, but worth a try (with the appropriate syntax changes for the shell you are using, of course).
According to the documentation, you should use
${env:PATH}
instead of${env.PATH}
.