declare in array and print the values randomly from array in bash script

2018-07-10T21:19:12

Here is my bash script code

declare -a types=("m4.xlarge" "m5.12xlarge" "m5d.12xlarge" "m4.large" "m4.16xlarge" "t2.2xlarge" "c4.large" "c5.xlarge" "r4.2xlarge" "x1e.4xlarge" "h1.16xlarge" "i3.16xlarge" );
echo "array declared"


for i in {1..100}
do

for (( i=1; i<${arraylength}+1; i++ ))   
 do

#index=$( jot -r 1  0 $((${#expressions[@]} - 1)) )
    randominstancetype=$[$RANDOM % ${#types[@]}];

    #randominstancetype=$( shuf -i0-1 -n1 $((${#types[@]} )) );
    #randominstancepvtiptype=$[$RANDOM % ${#pvtip[@]}];
        #randominstancepubiptype=$[$RANDOM % ${#pubip[@]}];
done
 done

I am trying to declare array and then print the elements inside the array randomly for around 100 times. Currently the name of the elements are not getting displayed instead it displays as 3 5 8 etc.. Anyhelp will be appreciated.

Copyright License:
Author:「user3906723」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/51266364/declare-in-array-and-print-the-values-randomly-from-array-in-bash-script

About “declare in array and print the values randomly from array in bash script” questions

Here is my bash script code declare -a types=("m4.xlarge" "m5.12xlarge" "m5d.12xlarge" "m4.large" "m4.16xlarge" "t2.2xlarge" "c4.large" "c5.xlarge" "r4.2xlarge&q
I've this script: an array of array, and a loop. Inside the loop, how can I print the key (foo) and the value (bar)??? #!/bin/bash declare -A combo=() combo+=(['foo']='bar') combo+=(['hello'
I am trying to loop through an array of directories using a bash script so I can list directories with their timestamp, ownership etc using ls -arlt. I am reviewing bash so would like some feedback...
I need to run a perl script in a bash array that will return certain values based on the string you provide. The perl script itself takes a user and a string and it will return the value based on the
I have been struggling with a new concept to me - associative arrays in a bash script. Here is simplified version of my code: #!/bin/bash declare -A MYID MYID[hello]=world tac /home/user/filename |
I created a little script that allow to make a rotation of values in an array. The goal was to shift the values to the right and that the last value of the array became the first value in order to
This works: $ BAR=(a b c) $ echo "${BAR[1]}" b This, however, doesn't: $ declare -A FOO $ FOO=(a b c) bash: FOO: a: must use subscript when assigning associative array bash: FOO: b: must use su
I need to test if certain environment variables are set before running my script. I'm using a technique from this answer: if [ -z ${var1+x} ] echo "var1 not set" exit 1 fi This works wel...
This is a sample of a problem I'm having - trying to declare an array in Upstart. I can run the declare line on the bash prompt but when done via an upstart script - it fails silently. descriptio...
I made a bash script to insert the result of nmap command to an array. The script is working on bash 4.3.30, but it does not work when I try to run it on bash 4.4.12. It looks like the array is emp...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.