Bash on Windows: script only progresses in -v mode

Viewed 18

I have a script which starts like this:

#!/bin/bash
echo "Running on OSTYPE: '$OSTYPE'"
DISTRO=""
CODENAME=""
SUDO=$(command -v sudo 2>/dev/null)

echo foo

When I run it as-is or with bash -x, it stops after the assignment to SUDO, I get as only output

+ DISTRO=
+ CODENAME=
++ command -v sudo
+ SUDO=

When I add -v to the bash invocation to get even more verbose output, the script runs normally and I see my "foo". I'm using bash 4.4.23 as shipped on https://git-scm.com/downloads

What is going wrong on my system and how can I debug this?

1 Answers

This happens because $(command ...) is a subshell.

Instead of set -x or bash -x create a file like follow inside your home folder:

.bash_env

set -x

So the set -x will be applied to any new bash instance and subinstance.

Related