I defined a shell function (let's call it
clock), which I want to use as a wrapper to another command, similar to the
time function, e.g.
clock ls -R.
My shell function performs some tasks and then ends with
I'd like this function to work even with shell built-ins, e. g.
clock time ls -R should output the result of the
time built-in, and not the
/usr/bin/time executable. But
exec always ends up running the command instead.
How can I make my Bash function work as a wrapper that also accepts shell built-ins as arguments?
Edit: I just learned that
time is not a Bash built-in, but a special reserved word related to pipelines. I'm still interested in a solution for built-ins even if it does not work with
time, but a more general solution would be even better.