How do I write a function `x' to replace builtin command `x', but still invoke the command from within the function?

How do I write a function `x' to replace builtin command `x', but still invoke the command from within the function?


This is why the `command' and `builtin' builtins exist. The
`command' builtin executes the command supplied as its first
argument, skipping over any function defined with that name. The
`builtin' builtin executes the builtin command given as its first
argument directly.

For example, to write a function to replace `cd' that writes the
hostname and current directory to an xterm title bar, use
something like the following:

cd()
{
builtin cd "$@" && xtitle "$HOST: $PWD"
}

This could also be written using `command' instead of `builtin';
the version above is marginally more efficient.



Home FAQ