Run/Debug BASH Scripts on Windows with Visual Studio Code๐Ÿ”—

Pavol Kutaj
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

3. links๐Ÿ”—

--

--

Pavol Kutaj

Today I Learnt | Infrastructure Support Engineer at snowplow.io with a passion for cloud infrastructure/terraform/python/docs. More at https://pavol.kutaj.com