Debugging Bash, using VSCode

Brian Sturgill bsturgill at ataman.com
Sat Jan 22 14:06:45 MST 2022


Visual Studio Code (VSCode) is an open source editor based on electron and
nodejs.
It is probably the best open source editor available, with wide support by
many, many projects.
It works equally well on Linux, Windows and MacOS. I use it routinely on
all three platforms.
One such project is the Bash Debugger Project and is a great way to get
started.

This is a quick start guide:

Install VSCode: https://code.visualstudio.com/Download
Click on the 4 box icon at the left (the top left box is raised away from
the other three).
Use the Search box at the top of the list of extensions list to find:
(I also just discovered Bash Extension, which installs all three plus more).
    Bash Debug
You might also want to install:
    Bash Beautify
    Bash IDE
    sudo apt install python-is-python3  # My version of Linux has only
version 3 installed.

IMPORTANT: Exit VSCode!

Create a directory somewhere using your shell and then cd to it and type:
    code .

Click the "explorer" button at the top left (looks like two sheets of
paper).
Now move your mouse near the name of the directory and click the new file
button...
Create a file.
#!/bin/bash
for f in /proc/*; do
   echo $f
done

If you installed Bash Beautify you'll see it with syntax coloring.
To the left of line 3 single click twice (pause between)... this will set a
breakpoint.
A red "led" will appear there.

>From the "Run" menu select "Add Configuration..."
Choose "Bash Debug".
You'll be placed into the file "launch.json".
Switch back to your bash file.
>From "Run" menu select "Start Debugging".
You'll stop at first line of code.
Select "continue" from debug controls at top.
You'll stop at line 3.
Hover over "$f"... you'll see it's value.
Add $f in the watch expressions at the left.
Hit "continue" a few times.

By now, you'll have a good idea of how the debugging works.
Hit the red square button to stop debugging.


-- 

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.nclug.org/pipermail/nclug/attachments/20220122/feb929c4/attachment.htm>


More information about the NCLUG mailing list