Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

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.