v217
v217

Reputation: 805

Howto use parameters in a function or alias in .bashrc on ubuntu?

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.

Upvotes: 0

Views: 86

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295825

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.

Upvotes: 3

Related Questions