Syntax

Bash Define a Function Syntax

In Bash, define a function: defines a reusable function — greet() { echo "Hi $1" }

Quick Answer

Syntax
greet() { echo "Hi $1" }
BashSyntax

Define a Function

Code example
greet() { echo "Hi $1" }

Defines a reusable function.

Learn More

How to define a function in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash Define a Function Syntax

Use greet() { echo "Hi $1" }.

Related Syntax References

Frequently asked questions

What is the Bash syntax for define a function?

Use this pattern: greet() { echo "Hi $1" }

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify