I have a custom 'runner'-script that I need to use to run all of my terminal commands. Below you can see the general idea in the script.
#!/usr/bin/env bash echo "Running '$@'" # do stuff before running cmd $@ echo "Done" # do stuff after running cmd I can use the script in bash as follows:
$ ./run.sh echo test Running 'echo test' test Done $ I would like to use it like this:
$ echo test Running 'echo test' test Done $ Bash has the trap ... DEBUG and PROMPT_COMMAND, which lets me execute something before and after a command, but is there something that would allow me to execute instead of the command?
There is also the command_not_found_handle which would work if I had an empty PATH env variable, but that seems too dirty.
"$@". Without the double quotes, your code is broken - it cannot handle quoted arguments correctly.eval. Just useeval "$1"instead of"$@", and run the script as./run.sh 'echo test'instead. (And make sure that the string you pass to the script is properly quotes, e.g.,./run.sh 'echo "This is an asterisk: *"'.