Unable to unbind a shell function
Asked Answered
A

1

0

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?

Actuate answered 27/6, 2009 at 21:49 Comment(0)
E
3

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

Ellon answered 27/6, 2009 at 22:4 Comment(7)
Oh another thing. You probably want to use "$*" instead of $1 in your function.Ellon
"$*" 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 %Afoul
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.Ellon
@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.Afoul
OS/X has man -S to specify the section. Also check out quick intro at rose-hulman.edu/~defoe/HowTo/index.html. Best of Luck.Ellon
I found a bug in the command. If I use even one option in man, then the command does not work.Afoul
@Masi: that's what Ryan was saying! if you want to use options, use $* or $@ instead of $1...Derisive

© 2022 - 2024 — McMap. All rights reserved.