A while ago, I had to execute a series of aliases of which the names were stored in an array. A simple for loop with en eval
call did the job.
Then I found out there are at least two more ways of evaluation in bash, so here are just a few links giving me a head start if I ever dig this up again:
Note that looping over parameters is different than over an array: [WayBack] Loop through an array of strings in Bash? – Stack Overflow
ou can use it like this:
## 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
Also works for multi-line array declaration
declare -a arr=("element1"
"element2" "element3"
"element4"
)
–jeroen
Like this:
Like Loading...