Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 9 down vote accepted

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
share|improve this answer
    
@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 Aug 3 '11 at 14:50

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.