0

I'm using Ubuntu within Windows Subsystem for Linux.

With the approach suggested by this answer I can run code when a new non-interactive shell is started:

$ cat ~/.bashenv
if [[ $- != *i* ]]; then
  echo foo
fi
$ export BASH_ENV=~/.bashenv
$ bash -c 'echo bar'
foo
bar

Now I am looking to setup a trap function with shopt extdebug enabled.

I tried something like this:

$ cat ~/.bashenv
#!/bin/bash
say_foo() {
  echo "foo"
}
set -T
trap 'say_foo' DEBUG
shopt -s extdebug
$ export BASH_ENV=~/.bashenv
$ bash -c 'echo bar'
foo
bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
bash: warning: cannot start debugger; debugging mode disabled
foo
bar

Is there any way to fix this?


A shorter way of reproducing the same issue:

$ bash --debugger -c 'echo hello'
bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
bash: warning: cannot start debugger; debugging mode disabled
hello

(Running an in-line bash script with --debugger is the same as setting extdebug in a file read via $BASH_ENV.)

Kusalananda
  • 333,661
Foo
  • 232
  • Who provided the bash executable on the system you are using? A package (what distribution?) or was it compiled locally? – Kusalananda Mar 14 '24 at 16:52
  • @Kusalananda it's the bash that came with the Ubuntu for Windows Subsystem for Linux. Is this behavior specific to my shell? – Foo Mar 14 '24 at 16:59
  • That helps if anyone wants to try to replicate the issue in order to solve it. Thanks. I will update your question text with this info. – Kusalananda Mar 14 '24 at 17:08
  • @Kusalananda Thank you. I didn't realize this might be specific to my shell. You can't reproduce this in a different bash then? – Foo Mar 14 '24 at 17:09
  • I appear to see the same issue on OpenBSD, which surprises me somewhat. In any case, letting people know what one's setup is is often good. – Kusalananda Mar 14 '24 at 17:13
  • I added a shorter way to reproduce the issue which does not require one to add a separate nevironment file. – Kusalananda Mar 14 '24 at 17:15
  • @Kusalananda ok thanks! – Foo Mar 14 '24 at 17:17

1 Answers1

0

The bash debugger was shipped in a separate package in Debian and Ubuntu called bashdb. However, it failed to be included in several Debian releases, and was removed. Usually, packages which are removed from Debian are also removed from Ubuntu unless someone chooses to maintain the packages manually for Ubuntu, and in this case, nobody did that.

The traditional way to debug shell scripts is with set -x (or bash -x), which should still continue to work here.

bk2204
  • 4,099
  • 7
  • 9