Creating an alias or function, need to be able to pass in a parameter

1

I want to wrap 3 lines of execution into an alias, but I also need to pass a parameter when I call it in terminal.

Do I need to create a function for this?

I'm new to this, but I know there are functions in bash also.

alias blah=some_call_here; some_other_call $1; some_thing_here

The $1 in the above is the value I want to pass in when I call the alias. So to call it I want it to look like:

blah "some text"

Not that it has to be text that I pass in.

user27449

Posted 2011-05-26T20:29:16.300

Reputation: 5 104

Answers

3

Aliases don't do parameters, so yes.

blah() { some_call_here ; some_other_call "$1" ; some_thing_here ; }

Ignacio Vazquez-Abrams

Posted 2011-05-26T20:29:16.300

Reputation: 100 516

how could I set a default value if $1 wasn't passed in? – user27449 – 2011-05-26T20:48:35.697

1

With one of the other forms of parameter expansion. http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

– Ignacio Vazquez-Abrams – 2011-05-26T20:50:27.470