Q:

Bash script for grepping string and placing them into array

I'm looking way to make bash script that greps output of command and place strings into array and be able to randomly select 1 string from the array for example every minute and place it as variable, time for randomly selecting needs to be configurable.
Command output:
string
string2
string3

Place of all these strings into array and randomly select one of them and place it as variable
desired result:
strings -> array <- randomly selecting from array every 1 minute and placing string selected as variable for further use 

A:

In bash, you can use readarray with command substitution to capture newline-separated outputs into an array; for exmaple:
readarray -t outputs < <(seq 10)

Where I've used seq 10 to produce some output. This results in:
$ declare -p outputs
declare -a outputs='([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6" [6]="7" [7]="8" [8]="9" [9]="10")'

To pseudorandomly select one of those elements every minute:
while :
do
  element=$(( RANDOM % ${#outputs[@]} ))
  var=${outputs[$element]}
  sleep 60
done

Noting that bash arrays start at index zero, the $(( )) arithemtic says to use the value of $RANDOM modulo the number of elements in the outputs array.

