13

How do I run and debug bash script from VSCode. I have this setup in my Ubuntu machine. Is there any way to configure so that when I say run it execute the bash script?

I did install the bash debug extension but I get this error

rogalmic.bash-debug-0.3.7/bashdb_dir/command/source.sh: line 41: /dev/stdin: No such device or address

kumar
  • 515
  • "You can create multiple terminals open to different locations and easily navigate between them. Terminal instances can be added by clicking the plus icon on the top-right of the TERMINAL panel or by triggering the Ctrl+Shift+` command. This action creates another entry in the drop-down list that can be used to switch between them." Source – DankyNanky Apr 18 '20 at 12:55

2 Answers2

8

You are getting that error because you need to attach a terminal to the script's input/output.

The bash debug extension works for me.

Try a debug launch configuration like this:

"configurations": [
  {
    "type": "bashdb",
    "request": "launch",
    "name": "Bash simple",
    "cwd": "${workspaceFolder}",
    "program": "${file}",
    "terminalKind": "integrated"   <---- This attaches the integrated terminal.
  }
]

Then open the script file in Code and press F5.

tebb
  • 81
1

Bash Code

From the run option in your integrated terminal, change the option to be the shell type you want to run your code in.

You can create multiple terminals open to different locations and easily navigate between them. Terminal instances can be added by clicking the plus icon on the top-right of the TERMINAL panel or by triggering the Ctrl+Shift+` command. This action creates another entry in the drop-down list that can be used to switch between them.

More information on the integrated terminals here.

  • but then how would I debug? The teminal will only allow me to execute the commands – kumar Apr 18 '20 at 15:21
  • @kumar Sorry, perhaps with the debug install you can contact the developer as per his repo? Slight misinterpretation of the question on my behalf. Can you also check you've got dependencies as required? – DankyNanky Apr 18 '20 at 15:25
  • Just installed the extension via Visual Code's marketplace and had no issues, and was functional. Perhaps reinstall Code and redownload the extension. I'd be curious as what the contents of source.sh was. – DankyNanky Apr 18 '20 at 15:29