Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to call a bash command which has been overridden with a function? I'd like to make pushd with no arguments alias to pushd . otherwise get normal behaviour.

I've tried

pushd(){
   if [ $# -eq 0 ]; then
      pushd .
   else
      pushd $@
   fi
}

but this seems to give infinite recursion. Normally I'd use the full path to whatever program I'm overriding, but push is a built-in bash thing, so that's not possible.

share|improve this question
up vote 7 down vote accepted

You should use the builtin command:

pushd(){
   if [ $# -eq 0 ]; then
      builtin pushd .
   else
      builtin pushd "$@"
   fi
}
share|improve this answer
1  
The entire function could even be rewritten as pushd() { builtin pushd "${1:-.}"; } – grawity Apr 5 '11 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .