How can I make a function interactive when using commands like ssh and less inside of a function?

function spo{
ls | less
}

For example how can I interact with less?

share|improve this question
That Just Works for me. – ams May 22 '12 at 13:48
Why would you make this a function and not an alias? – uther May 22 '12 at 13:49
This question might be nonsense let me figure out what I am doing wrong =/ – James Andino May 22 '12 at 13:56
4  
I realized my mistake. In my working example I was overriding the command with the same function name and just dumping into a recursive loop. I think this question should be closed because it makes no sense! – James Andino May 22 '12 at 14:00
Good job doing your homework a reporting back +1 – Tim May 22 '12 at 18:44

closed as not a real question by James Andino, sr_, Shawn J. Goff, manatwork, Kevin May 22 '12 at 14:40

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

Note that the function keyword is a bash-ism that serves no real purpose. You should avoid it and add a bit more portability to your scripting.

If you want to create a shell function which overrides a native command, then have the shell function invoke the native command, use the command shell built-in like this:

ls () {
    command ls | less
}

See the shell man page section on shell builtins for a description of command.

share|improve this answer

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