I am writing a a bash script echoo.sh
with the intention of echoing commands before they are executed. I source the script inside .bashrc
. But it does not affect other bash scripts that I run. Below is the code I have so far:
echoo.sh
#!/usr/bin/env bash
shopt -s extdebug
get_hacked () {
[ -n "$COMP_LINE" ] && return # not needed for completion
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # not needed for prompt
local this_command=$BASH_COMMAND;
echo $this_command;
}
trap 'get_hacked' DEBUG
When I open a shell and run any command - It works. But for stuff in a script file it doesn't work.
SOME FURTHER TRIES:
- I tried sourcing the
.bashrc
file within the test script - it didn't work. - I sourced
echoo.sh
inside of the test script and it worked.
So, I am trying to understand
- Why doesn't it work if I just source my script in
.bashrc
for stuff that runs in scripts? - Why doesn't further try #1 work when #2 does.
And, finally, what can I do such that I don't have to source echoo.sh
in all script files for this to work. Can I source my script in one place and change some setting such that it works in all scenarios.
]shopt
? With the bracket? – ilkkachu Feb 06 '18 at 19:49