Languages
[Edit]
EN

Bash - iterate through array values

3 points
Created by:
Khloe-Kaiser
578

This article will show you how to iterate through array values in Bash.

Quick solution:

#!/bin/bash

array=(Tom Kate Mary)

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

Example output:

Tom
Kate
Mery

 

Alternative solution

It is possible to use an alternative approach to access array items - it is ${array[*]}.

#!/bin/bash

array=(Tom Kate Mary)

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

Example output:

Tom
Kate
Mery

Alternative titles

  1. Bash - iterate over values
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - iterate through array values
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