Super User is a question and answer site for computer enthusiasts and power users. 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

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


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

Your Answer


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.