how can I select one of the 6 arrays at random? [closed]

0
#!/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[@]

How can I select one of the 6 arrays at random and print its contents?

    
asked by Eduardo Espinal 28.10.2017 в 23:28
source

1 answer

1

You have a syntax error where it says

"Sin anestecia"

must say

"Sin anestesia".

Finally, jokes aside, you do not understand what you want to do well. If you want to form a sentence by randomly joining an element of each declared array, the way would be to generate 6 random values and ask for the position of these in the arrays above. And eye, your arrays have 4 elements, so you have to apply module 4 and not module 6.

#!/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 anestesia " "Sin compromiso " "Feis to feis " "Sin Miedo ");

a=$(( $RANDOM % 4 ));
b=$(( $RANDOM % 4 ));
c=$(( $RANDOM % 4 ));
d=$(( $RANDOM % 4 ));
e=$(( $RANDOM % 4 ));
f=$(( $RANDOM % 4 ));

echo ${_0[a]} ${_1[b]} ${_2[c]} ${_3[d]} ${_4[e]} ${_5[f]};

Which would generate phrases like

Bebe Voy a Encenderte Lento Toda la Noche Sin compromiso
Bebe Yo puedo Amarte Fuerte Todo el dia Sin Miedo
Mami Yo puedo Encenderte Fuerte Todo el dia Feis to feis

But as I said before, it's not clear to me what you want to do. If you want your program to print the values of one of the 6 arrays in random order, the logic is different.

In other words, if you want your program to return the second array "I want" "I can" "I come to" ... given a parameter entered by console or randomly generated, what you're trying to do implicitly it is a nested associative list. And that in bash does not exist.

    
answered by 29.10.2017 в 18:45