Syntax

Bash Create an Array Syntax

In Bash, create an array: creates an indexed array — fruits=(apple banana cherry)

Quick Answer

Syntax
fruits=(apple banana cherry)
BashSyntax

Create an Array

Code example
fruits=(apple banana cherry)

Creates an indexed array.

Learn More

How to create an array in Bash

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

Bash Create an Array Syntax

Use fruits=(apple banana cherry).

Related Syntax References

Frequently asked questions

What is the Bash syntax for create an array?

Use this pattern: fruits=(apple banana cherry)

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