4

In my .bash_profile file, I'd like to setup a single command alias that is two commands that execute one after another. The first command takes an argument from the command line and the second is actually script (located in ~/bin with execute permissions).

My profile file has this:

alias pd='function pd2() { pushd "$@"; set_title_tab; }'

I attempt to execute it in the shell like so:

$ pd ~/Documents/

and I get an error:

-bash: syntax error near unexpected token `~/Documents/'

set_title_tab is a shell script written by William Scott

Is there a better way to accomplish this?

2 Answers 2

12

aliases do not support input parameters, and there's no need to wrap functions in aliases. Simply use a function:

pd() {
    pushd "$@"
    set_title_tab
}

pd ~/Documents
1
  • @StephanKeene: This answer is correct, you don't need an alias for this. You can define functions in your bash profile and call them just like other command names or aliases from the command line.
    – Caleb
    Commented Aug 3, 2011 at 14:50
5

Why not this:

pd () { pushd "$@"; set_title_tab; }

What you have right now is a function definition inside an alias which is ... unusual. Once you define a function (like I did with pd above) you can use it just like any other command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .