tags:

views:

68

answers:

1

This question is based on the thread.

I have the shell function

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

The problem is there exists the command man.

How can you replace the command with my command?

+3  A: 

Replace man "$1" with the pathname: /usr/bin/man. Or change it to use 'which man' within backquotes. Then run your script in the current shell. On bash/ksh you need to save your script in some file, say man.sh and then run it as '. ./man.sh'.

cat > man.sh
function man()
{       
    /usr/bin/man "$1" > /tmp/manual; less /tmp/manual 
}
^D

. ./man.sh

You get the idea. You can undefine the function at any time: unset -f man

Ryan Oberoi
@Ryan: Thank you for your answer! It solves the problem!
Masi
Oh another thing. You probably want to use "$*" instead of $1 in your function.
Ryan Oberoi
"$*" seems to prefer all parameters from 1,2,3,... This may be useful. However, I cannot understand how you read manuals by % man emacs vim %
Masi
Well. $* will be useful when you use man -3C printf. And your function will then support all the semantics of the traditional man. If you run man emacs vim, you can skip to the next man by typing q on my system.
Ryan Oberoi
@Ryan: I use OS/X. It does not have the option -3C: What is its purpose? --- The "$*" does not work as you describe in OS/X. I also run "$1" "$2" unsuccessfully. --- Could you explain which features I miss if I do not use $*, please.
Masi
OS/X has man -S to specify the section. Also check out quick intro at http://www.rose-hulman.edu/~defoe/HowTo/index.html. Best of Luck.
Ryan Oberoi
I found a bug in the command. If I use even one option in man, then the command does not work.
Masi
@Masi: that's what Ryan was saying! if you want to use options, use $* or $@ instead of $1...
Stobor