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

I'm trying to create a function in .bashrc to shortcut my MAMP commands. I want to do something like this:

mamp config

  • Opens up MAMP's httpd.conf file for editing.

mamp restart

  • Restarts the MAMP server.

I created a function in .bashrc called mamp():

function mamp {
  if [$1 == "config"]; then
    nano /Applications/MAMP/conf/apache/httpd.conf
  fi

  if [$1 == "restart"]; then
    /Applications/MAMP/Library/bin/apachectl restart
  fi
}

But that doesn't seem to work.

I get this error -bash: [config: command not found

share|improve this question
up vote 2 down vote accepted

I think all you need to do is add spaces in the if tests,

e.g.

if [ $1 == "config" ]; then
share|improve this answer
    
Wow, thank you. That took care of it. I didn't realize it was that picky about spacing. – zakangelle Jun 18 '13 at 16:50
    
You are welcome. spacing around [ and ] helps bash with the parsing of the statement. – suspectus Jun 18 '13 at 16:53
3  
@zakang: Well, [ is a command. Putting a space between [ and $1 is just like putting a space between mamp and config in mamp config. – grawity Jun 18 '13 at 16:56
    
@grawity: That's good to know. I work with JavaScript on a daily basis, and it's much looser with stuff like this, so I just thought it was a formatting preference. – zakangelle Jun 18 '13 at 16:58
1  
I'd also make sure you have a parameter. [ $1 == "config" ] will choke somewhat cryptically if there is no $1 parameter. Putting [ $# -ne 0 ] && return will do so. – Rich Homolka Jun 18 '13 at 17:29

You must log in to answer this question.

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