Here is my attempt:rand_var() {printf %s\n ${${!1}[RANDOM % ${#${!1}[@]}]}}And I run it like thisarray=(something somethingelse test)rand_var arrayHowever, it tells me bad substitution. I think it may have something to do with the variables and quoting but I can't figure it out, I use ${!1} so that it acctually uses the contents of the variable and not just array. This line has worked before when I specify the variable name instead of ${!1}.
How would I create this function to choose a random variable from an array?
bash;array