Bash preexecute
- by Alex_Bender
I'm trying to write bash command wrapper, which will be patch bash current command on the fly. But i'm faced with the problem. As i'm not a good Shell user, i can't write right expression of variable assignment in string. See bellow:
I'm set trap to preexecute, through this:
alex@bender:~$ trap "caller >/dev/null || xxx \"\${BASH_COMMAND}"\" DEBUG;
I want change variable BASH_COMMAND, do something like BASH_COMMAND=xxx ${BASH_COMMAND} but i don't know, how i need escaping variables in this string
NOTE: xxx -- my custom function, which must return some value, if in end of command situated word teststr
function xxx(){
# find by grep, if teststr in the end
`echo "$1" | grep "teststr$" >/dev/null`;
# if true ==> do
if [ "$?" == "0" ]; then
# cut last 6 chars (len('teststr')==6)
var=`echo "$1" | sed 's/......$//'`;
echo "$var";
fi }
How can i do this stuff?:
alex@bender:~$ trap "caller >/dev/null || ${BASH_COMMAND}=`xxx $BASH_COMMAND`" DEBUG;