Languages
[Edit]
EN

Bash - create array

0 points
Created by:
Teilsa
345

This article will show you how to create an array in Bash.

 

There are several ways to create an array in Bash:

#!/bin/bash

# simple array creation 
my_array=(1 two 3 4 five 6)

# using declare
declare -a my_array=(1 two 3 4 five 6)

# assign only one value
my_array[0]=1

Iterating over array example

#!/bin/bash

array=(Tom Kate Mary)

for i in "${array[@]}"
do
	echo $i
done

 Output:

Tom
Kate
Mery

Note:

Also check out the article on iteration over an array - Bash - iterate through array values.

Bash

Bash - create array
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join