Ir para conteúdo
View in the app

A better way to browse. Learn more.

Portal do Host

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Postado

Olá,

Alguém sabe como pegar um índice do array aleatório usando shell script (bash)?

No PHP seria algo do tipo array_rand().

 

Abs.


Postado

Partindo do pressuposto que você já conhece o tamanho de seu Array:

No exemplo abaixo, eu sorteio um IP qualquer de um array ips, onde deve ser sorteado um elemento de um array de 12 posições. Lembre-se que em Shell a primeira posição do array é definido no índice [1] e não [0] como no PHP.

${ips[shuf -i 1-12 -n 1]}
Se for um array de tamanho desconhecido, basta medi-lo antes usando:

qntd =${#ips[@]} 
 

Postado
  • Autor

Deu erro.. :/

 

line 5: shuf -i 1-12 -n 1: syntax error in expression (error token is "1-12 -n 1")

Postado
  • Autor

Consegui, fiz da seguinte forma: 

ips=("xxx" "yyy" "zzz")
ips_shuf=($(shuf -e ${ips[*]}))
echo ${ips_shuf[1]}


Visitante
Este tópico está impedido de receber novos posts.

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Informação Importante

Concorda com os nossos termos?

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.