How to invoke a shell built-in explicitly?
Bash has a (builtin) command builtin
, which does exactly what you need. Replacing cd
with builtin cd
in your function will fix the recursion.
The command
builtin forces a command name to be interpreted as a built-in or external command (skipping alias and function lookup). It is available in all POSIX shells including bash.
cd () { command cd "$@" && pushd "$@"; }
(Note that this example is a bad one: it doesn't work with relative paths, and you might as well just type pushd
in the first place.)
In bash and zsh (but not ksh), you can use builtin
to force a command name to be interpreted as a builtin, excluding aliases, functions and external commands.