I am trying to build a pre-exec checker in bash (using bash-preexec.sh
)
In order to fail the command when the pre-exec hook fails, I need to run shopt -s extdebug
(which fails the command when trap DEBUG command returns non-zero RC).
If I run shopt -s extdebug
in my shell as a command, this works perfectly fine (the preexec checker just grepped for "OK" in a file containing word "FAIL", so command shouldn't execute):
> grep shopt .bashrc
> bash
bash-4.1$ echo TEST2
TEST2 <=== Expected, since I didn't turn on extdebug yet
bash-4.1$ shopt -s extdebug > /dev/null 2>&1
bash-4.1$ echo TEST2
bash-4.1$ # WHAT WAS EXPECTED. Command failed to execute.
However, when I add the command to my .bashrc, it has no effect:
> grep shopt .bashrc
shopt -s extdebug > /dev/null 2>&1
> bash
bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
bash: warning: cannot start debugger; debugging mode disabled
bash-4.1$ echo TEST2
TEST2