How to Write Bash For Loop Array

preview_player
Показать описание
The Bash For Loop Array enables you to create a string so that you make a loop which can be seen on the output screen of Linux.

In this tutorial we will show you how to write a bash for loop array. This command let's your make a string and form a loop that is repeated in the output. Loops and arrays are easy to create in Linux.
To understand how to create a loop array, follow the tutorial steps given below.

Step 1 -- Declare a variable and create a string

First of all, we will declare an array variable over here. Now we will create a string of element 1, 2 and 3 over here, and we will assign it in the array variable that we have already declared before.
declare --a arr=(element1 element2 element3)

Step 2 -- Loop the array

Next, we will loop through the above array and display all the elements inside the array.
For that, we will use the "at the rate" sign over here.
for i in ${arr[@]}

Step 3 -- View the output on the screen

With that done, the output of the bash loop array will be displayed on the screen.
And there you have it, a basic for command for loops and arrays written in bash.
do
echo $i
done
Рекомендации по теме
Комментарии
Автор

i trying to get the output of who command insto an array separated by new lines as thats how its outputted from who command so i can make a menu from it how can i do this please?