Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

Possible Duplicate:
On a Mac, how can I group together commands I want run into a alias?

I have been using aliases for a while now but can't seem to figure out how to 'chain' commands properly. For instance, is there a way to type in one alias and have it chain multiple commands, like this?

'cd /Applications/MAMP/htdocs/V3/wp-content/themes/V3/'
mate .
open /Applications/MAMP/
open -a Safari http://localhost:8888/
share|improve this question

marked as duplicate by Daniel Beck, slhck, Ƭᴇcʜιᴇ007, studiohack Oct 30 '11 at 3:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 4 down vote accepted

Use shell functions:

function mampMate() {
    cd /Applications/MAMP/htdocs/V3/wp-content/themes/V3/
    mate .
    open /Applications/MAMP/
    open -a Safari http://localhost:8888/

Add these to your .bash_profile and run by entering


You can even pass parameters and access them using their index as $1, $2, etc.

function foo() {
    echo "1: $1"
    echo "2: $2"

$ foo bar baz
1: bar
2: baz

One step further, and making your script more independent of your preferred shell, are scripts. Create a file named and add the following:

#!/usr/bin/env bash
cd /Applications/MAMP/htdocs/V3/wp-content/themes/V3/
mate .
open /Applications/MAMP/
open -a Safari http://localhost:8888/

This won't change your working directory though, as it won't affect your shell session.

Run chmod +x and place it in a directory on your $PATH.

share|improve this answer
Perfect, thank you for the explanation! – Tom Wahlin Oct 29 '11 at 19:56

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