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.

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 there anything to watch out for if you wanted to override ls? Is there a more reliable way of getting pagination out of ls?

For example:

function ls() { command ls -hp $@ | more; }
share|improve this question
5  
You need to quote "$@". – jordanm Dec 1 '12 at 19:36

No harm doing it your way as it may be scoped to interactive shells and not impact scripts.

Only danger (and it may be a big one if you work on wide range of systems) - you may get used to a habit of using a non-standard mapping unnecessarily.

Particularly with ls there are some established best practices in the industry.

E.g. many systems implement ll as a pagination variant of ls. It's easier to type and you can reasonably expect it to be already present in a new system you encounter.

To see which shortcuts are readily available to you type alias and set.

share|improve this answer

You don't use ls in a script (don't parse ls), so that function will only be used by you in an interactive shell. Nothing to watch out for. Aside from adding double quotes around "$@", that's the best way to do it.

share|improve this answer

Your Answer

 
discard

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