Eduardo Espinal
Eduardo Espinal

Reputation: 11

Select random array variable name in bash

#!/bin/bash

_0=("Mami"  "Bebe"  "Princesa"  "Mami")
_1=("Yo quiero " "Yo puedo "  "Yo vengo a " "Voy a ")
_2=("Encenderte"  "Amarte"  "Ligar"  "Jugar")
_3=("Suave"  "Lento"  "Rapido"  "Fuerte")
_4=("Hasta que salga el sol " "Toda la noche "  "Hasta el amanecer "  "Todo el dia ")
_5=("Sin anestecia " "Sin compromiso " "Feis to feis " "Sin Miedo ")

b=$(( $RANDOM % 6 ))

echo _$b[@]

I want to select randomly one array and print its value.

Upvotes: 0

Views: 68

Answers (1)

Vasan
Vasan

Reputation: 4956

Please see this answer. Adapting it to your script, the last two lines become:

b=_$(( $RANDOM % 6 ))[@]
echo ${!b}

Upvotes: 1

Related Questions