Run/Debug BASH Scripts on Windows with Visual Studio Codeđź”—
2 min readSep 28, 2021
The aim of this pageđź“ť is to start with BASH in Visual Studio Code on Windows, and eventually getting to run/debug scripts just by pressing F5. I was kind of skeptical about WSL, I suspected it would somehow interfere with my perfect existing OS/Powershell setup, etc (I was trying to set this up for Clojure and gave up). But no, it really is easy & fast as pasting a single command, 1 reboot, downloading Ubuntu (0.5 GB), and a couple of steps in VsCode.
1. WSLđź”—
- We start by setting up Windows Subsystem for Linux by running the following in an elevated Powershell Prompt
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
- Go to Windows Store → Install Ubuntu 20.04 LTS → Reboot
- Run the downloaded Ubuntu as a normal → Select username/password → Done
2. VSCodeđź”—
- Install Bash Debug from Visual Studio Marketplace
- Go to Integrated Terminal → Select newly appeared Ubuntu 20.04 (WSL)
- Create
hello.sh
→ Write a simple loop to print the range<1,20>
in the consosoe
for i in {1..20}
do
echo "$i"
done
- Open
launch.json
and paste the following
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug",
"cwd": "${workspaceFolder}",
"program": "${file}",
"args": []
}
- Press F5 in
hello.sh
, twice to just run without debugging - Go to DEBUG CONSOLE to get the output → Done