Search code examples
manpageif-statement

To fix a bug in Less' command by noting no. of parameters


This question is based on this thread.

The code

function man()
{       
    man "$1" > /tmp/manual; less /tmp/manual 
}

Problem: if I use even one option, the command does not know where is the wanted-manual

For instance,

man -k find

gives me an error, since the reference is wrong. The command reads -k as the manual.

My attempt to solve the problem in pseudo-code

if no parameters
    run the initial code
if one parameter
    run: man "$2"
...

In other words, we need to add an option-check to the beginning such that

Pseudo-code

    man $optional-option(s) "$n" > /tmp/manual; less /tmp/manual

where $n

  • n=1 if zero options
  • n=2 if 1 option
  • n=3 if 2 options
  • ....

How can you make such an "option-check" that you can alter the value of $n?

Developed Problem: to make two if loops for the situations from n=1 to n=2


Solution

  • How about passing all the arguments

    function man()
    {       
        man $@ > /tmp/manual; less /tmp/manual 
    }
    

    What is the bug in less which you mention in the title?