Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

loop from array bash

#!/bin/bash
# declare an array called array and define 3 values
array=( one two three )
for i in "${array[@]}"
do
	echo $i
done
Comment

array and for loop bash

myArray=('Apple' 'Banana' 'Orange')
for i in "${myArray[@]}";
do
  echo $i
done
Comment

loop over array of strings bash

## declare an array variable
declare -a arr=("element1" "element2" "element3")

## now loop through the above array
for i in "${arr[@]}"
do
   echo "$i"
   # or do whatever with individual element of the array
done

# You can access them using echo "${arr[0]}", "${arr[1]}" also
Comment

bash for loop string array

## declare an array variable
declare -a arr=("element1" "element2" "element3")

## now loop through the above array
for i in "${arr[@]}"
do
   echo "$i"
   # or do whatever with individual element of the array
done
Comment

bash array forloop

#!/bin/bash
## declare an array variable
declare -a array=("one" "two" "three")

# get length of an array
arraylength=${#array[@]}

# use for loop to read all values and indexes
for (( i=0; i<${arraylength}; i++ ));
do
  echo "index: $i, value: ${array[$i]}"
done
Comment

Bash script Array + For loop

month=("JAN" "FEB" "MAR" "APR" "MAY" "JUN")

for i in ${month[@]}
do
        echo -e "Month name is: c"
        echo "$i"
done
        echo
        echo -e "Total Month are: c"
        echo "${#month[@]}"
        echo
Comment

bash array and for loop

ss="abcdefghi"
my_array=( `echo $ss | grep -o . ` )

### without for loop ###########
declare -a NewArray=("${my_array[@]}")
echo ${NewArray[@]}

########### using for loop #################
for i in "${my_array[@]}"
do
     new_array+=($i)
done

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





Comment

PREVIOUS NEXT
Code Example
Shell :: install pytorch for cuda 10.0 
Shell :: delete folder terminal mac 
Shell :: linux get user id 
Shell :: remove file from stage git 
Shell :: centos reboot 
Shell :: bash store file in array 
Shell :: apt install xfce 
Shell :: error after docker uninstall 
Shell :: sudo add permissions to user 
Shell :: kill a process at a port 
Shell :: installing xlswriter 
Shell :: git merge abort 
Shell :: command line size of directory 
Shell :: bash rename file 
Shell :: pause bash script 
Shell :: remove global packages npm 
Shell :: install grafana 
Shell :: multi line comment in bash shell 
Shell :: git no ssl verify 
Shell :: slow internet wifi speed on ubuntu 18.04 
Shell :: angular add component 
Shell :: set multiple git username and password 
Shell :: rancher 2 on ubuntu 20.04 
Shell :: conda install multiprocess 
Shell :: install python debian 
Shell :: husky install 
Shell :: installing webpack-cli 
Shell :: git abort changes 
Shell :: installing docker on amazon linux 
Shell :: bash script get ip address of eth0 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =