0

For example this does not work:

man(){ man -H "$1" & } 

But I need the parameter, because I want the command to end with an ampersand.

This doesn't work as well:

man(){ firefox & man -H } 

I don't want firefox to close if the firefox process is started by man and man is terminated.

9
  • 1
    If you hadn't deleted your prior question, I would have finished extending my answer there. Commented Sep 23, 2016 at 17:28
  • 1
    BTW, expounding on "does not work" is generally a good idea. What does it do? How do you know it doesn't work? Have you run type man to ensure that it's actually defined in your current shell instance? Etc. Commented Sep 23, 2016 at 17:29
  • BTW, what follows -H is supposed to be the name of your browser. I assume you'd want man() { man -H /path/to/firefox "$@" & }, or such, instead. Commented Sep 23, 2016 at 17:31
  • and even then, that won't have any effect unless the man page you want is actually in HTML format, so I'm not sure why running man -H ...anything... & is ever a thing you'd actually want to do. Commented Sep 23, 2016 at 17:31
  • Also? Use set -x to make your shell log what it's doing to stderr (or the file descriptor pointed at with BASH_XTRACEFD on 4.x, if you want to redirect it to a log file -- which is actually a good idea, if man is being invoked). If you think it's not actually running the function, put that command first, and see if that's true. Commented Sep 23, 2016 at 17:33

1 Answer 1

3

The parameter isn't a problem. The recursion is the (most severe immediate) problem.

When you have a function named man call man, it calls itself. You're starting an unbounded set of background shells. Using command will prevent that recursion, as it bypasses function lookup.

One change I would suggest making with respect to parameter-passing is using "$@", so the full set of parameters is passed through, not only the first one:

man() { command man -H "$@" & } 

Note, by the way, that at least for the BSD implementation used by Apple, man -H expects the name of a program that can convert HTML to text to be the immediate following argument. If you think that, for instance, man -H bash & will start the bash man page in a web browser in the background... well, that may be the case on your platform, but it's not universally true.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.