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 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

Bash script using input to iterate through array

echo -e "Enter value between 0-5: c"
read -r readusr

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

echo -e "User chosen month is: c"
echo ${month[$readusr]}

echo -e "All months are: c"
echo ${month[@]}

echo -e "Numbers of months are: c"
echo ${#month[@]}
Comment

PREVIOUS NEXT
Code Example
Shell :: bash script create file if not exist 
Shell :: no upgrade brew 
Shell :: linux remove mysql server 
Shell :: upgrade git on centos 7 
Shell :: linux set python 3 as default 
Shell :: error cannot refresh snap-store snap snap-store has running apps (ubuntu-software) 
Shell :: pm2 start timestamp 
Shell :: cmake must be installed to build dlib 
Shell :: nginx certbot ubuntu 
Shell :: refresh bash_profile 
Shell :: docker: Error response from daemon: dial unix docker.raw.sock: connect: no such file or directory 
Shell :: find empty files linux 
Shell :: chocolatey list installed 
Shell :: robo 3t download for ubuntu 18.04 
Shell :: installer pip3 linux 
Shell :: kubectl list context 
Shell :: show mac address in ubuntu 
Shell :: (‘08001’, ‘[08001] [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection (0) (SQLDriverConnect)’) 
Shell :: git check ssh connection 
Shell :: install yarn with npm 
Shell :: prevent duplicate history line on bash history 
Shell :: iis stop 
Shell :: sqlite laravel 
Shell :: remove the last commit git without losing changes 
Shell :: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? 
Shell :: search for a commit in git logs 
Shell :: install docker kali linux 
Shell :: bash get width of terminal 
Shell :: npm i mui 
Shell :: ubuntu certbot nginx 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =