I'm at a Hackathon right now so if someone would answer this soon, you'd be doing me a huge favor.

I've written a function called ls() in my .bashrc that looks like this:

ls() {

  if(some condition);
    do something


But here when it goes to the else part, it just enters an infinite loop

How can I call the original ls system call in else Or, how can I make ls behave differently in one folder and normally in the others.

  • did you try to call ls with full path in your else condition? /usr/bin/ls
    – herrhansen
    Jun 16 '13 at 18:15

You are looking for command:

command [-pVv] command [arg ...]

Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH are executed. If the -p option is given, the search for command is performed using a default value for PATH that is guaranteed to find all of the standard utilities. If either the -V or -v option is supplied, a description of command is printed. The -v option causes a single word indicating the command or file name used to invoke command to be displayed; the -V option pro‐ duces a more verbose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if not. If neither option is supplied and an error occurred or command cannot be found, the exit status is 127. Otherwise, the exit status of the command builtin is the exit status of command.


$ pwd() {
> echo 'command test'
> command pwd
> }
$ pwd
command test

There is also builtin, which is more restrictive:

builtin shell-builtin [arguments]

Execute the specified shell builtin, passing it arguments, and return its exit status. This is useful when defining a function whose name is the same as a shell builtin, retaining the functionality of the builtin within the function. The cd builtin is commonly redefined this way. The return status is false if shell-builtin is not a shell builtin command.


You may also be interested in which, which gives you the path to the program in your $PATH with that name.

$ which ping

(Though I'd recommend Nykakin's answer, as it solves your problem. This is just another tool for anyone interested)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.