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 do know the JavaScript syntax:

var functionName = function(some perameter){

some code here; };

but what is the syntax for a function in bash?

share|improve this question
2  
You are getting downvoted because you can find an answer to this with 5 minutes worth of web search. In general, questions that can be answered with RTFM get downvoted. – terdon Jan 21 '13 at 19:06

There are two ways to create Bash functions:

function function_name { 
  # your commands
} 

Or:

function_name () { 
  # your commands
} 

Both are equivalent. Read more about it, for example in the Advanced Bash-Scripting Guide under Functions or in the Bash Reference Manual.

share|improve this answer
    
Three ways, technically: function foo () { is also allowed. Only one of the keyword function and the parentheses are required, though. The function keyword is a bash extension, though; your second example is the standard way of defining a function and will work in any POSIX-compatible shell. – chepner Jan 21 '13 at 22:44

You must log in to answer this question.

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