Namely: I want to alias tail -f to less +F but let tail with any other parameter supplied work the same way as before.


This is slightly beyond the powers of what shell aliases provide (assuming bash). You could define a function:

function tail() {
    if [ "$1" == '-f' ]; then
        less +F "$@"
         command tail "$@"

When you type tail, this will now refer to the function defined above, which checks its first argument, if any, for equality with -f, and if it matches, runs less +F on the rest of the original arguments (shift removes the first of the original arguments, -f). Otherwise, it calls the command tail with all of the original arguments (calling the built-in command is necessary to avoid an infinite loop; without it, tail would refer to the function being defined, causing an infinite loop).

  • What does shift exactly do? – syntagma Mar 30 '15 at 17:54
  • I just pushed an edit to answer this. – dhag Mar 30 '15 at 17:59

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.