Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I write a function in zsh that invokes an existing command with the same name as the function itself? For example, I've tried this to illustrate my question:

function ls 
{
    ls -l $1 $2 $3
}

But I see this when I execute it with ls *:

ls:1: maximum nested function level reached

I assume this is because the function is being called recursively. How I can avoid this?

(this is a crude example, and in this case an alias would do the job, but I have a more complex example where an alias isn't suitable and so I need to write a function).

share|improve this question

1 Answer

up vote 9 down vote accepted

What is happening is that you are recursively calling your ls function. In order to use the binary, you can use ZSH's command builtin.

function ls {
    command ls -l "$@"
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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