Debugging Bash on Windows

Using the WSL and vscode to debug bash scripts on windows
debugging bash vscode windows

TODO:(sblack4) finish links when I get internet

Debugging Bash on Windows

Using the WSL and vscode to debug bash scripts on windows

[bash](#TODO:wikipedia on bash) (in this case the windows subsystem for linux), visual studio code, docker these are a few of my favorite things!

bash on ubuntu on windows

is it overkill when your running wsl in a terminal emulator (cmder)

I’ve toyed with docker but hadn’t seriously used it for work. With access to the cloud it’s (usually) easy to get a VM with the services I want on it! That changed when I saw how a easy it was for a few of my peers to spin up containers with docker and werker! There’s a great tutorial by a friend of mine, here on github that covers container native development.

The problem

I want to play with oracle streaming analytics in docker and some of the other docker images in oracle’s docker library. There are shell scripts to assist in setting up the image which would be super helpful if I was running linux! Working in a large corporation that makes heavy use of certain programs, cough, office, cough, makes using windows a lot more conveinient. Not to mention I never have to worry about drivers for third party devices (anyone who has tried to use linux as their personal computer will know what I mean)!

Although with google’s [chrome os](#TODO:wiki chomeos) becoming so common, and most services moving to a subscription-based SaaS model (Office 365, G-Suite) it has never been easier for everyday use of linux.

The fix

Windows Subsystem for Linux (wsl)

Windows 10 introduced the wsl starting out with ubuntu on windows, which is why you’ll see me use apt-get. I love ubuntu but I work most with red-hat based distrubutions like [oracle linux](#TODO: wiki oracle linux). Linux Mint has caught my eye recently though… :smiley:

In this case [Bash Debug](#TODO: bash debug page) lets you step through bash scripts (I didn’t know you could debug bash at all!)

Bash Debug

Bash debug takes a little set-up. Here’s my $BASEDIR/.vscode/launch.json it launches the bash script in view with three arg -v 12.2.1 -A -s

    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit:
    "version": "0.2.0",
    "configurations": [
            "type": "bashdb",
            "request": "launch",
            "pathBash": "C:\\Windows\\System32\\bash.exe",
            "name": "Bash-Debug (simplest configuration)",
            "program": "${file}",
            "args": [
                "-v 12.2.1",

The Results

Very simply, this is awesome. I’ve been struggling to improve my bash recently, this will help.

bash debug on windows

I managed to figure out how to launch docker from the wsl too! Even though docker is aliased in the ~/.bash_aliases bash doesn’t automatically extend these aliases in scripts. By substituting docker for the absolute path and call to launch docker.exe

This was the script that needed fixing - some of the downloads turned out to be outdated and the links were broken

# BUILD THE IMAGE (replace all environment variables)
BUILD_START=$(date '+%s')
/mnt/c/Program\ Files/Docker/Docker/resources/bin/docker.exe build --force-rm=$NOCACHE --no-cache=$NOCACHE $PROXY_SETTINGS -t $IMAGE_NAME -f osa-dockerfiles/oracle-stream-analytics/dockerfiles/12.2.1/Dockerfile.$DISTRIBUTION . || {
  echo "There was an error building the image."
  exit 1