6

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.

Hennes
  • 64,768
  • 7
  • 111
  • 168
Andrew Wood
  • 1,279
  • 2
  • 15
  • 24

1 Answers1

9

You should use the builtin command:

pushd(){
   if [ $# -eq 0 ]; then
      builtin pushd .
   else
      builtin pushd "$@"
   fi
}
u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
cYrus
  • 21,379
  • 8
  • 74
  • 79