Skip to content

Instantly share code, notes, and snippets.

@joerx
Created April 8, 2015 04:56
Show Gist options
  • Save joerx/bd2ea764ceaa182c01da to your computer and use it in GitHub Desktop.
Save joerx/bd2ea764ceaa182c01da to your computer and use it in GitHub Desktop.
Random item from list in bash
# Array with expressions
dishes=(":hamburger:" ":pizza:" ":poultry_leg:" ":rice:" ":curry:" ":ramen:" ":spaghetti:" ":sushi:")
# Seed random generator
RANDOM=$$$(date +%s)
# Get random expression...
selecteddish=${dishes[$RANDOM % ${#dishes[@]} ]}
echo $selecteddish
@joerx
Copy link
Author

joerx commented Apr 8, 2015

Gracefully copied from somebody on Stackoverflow, modified by me to make it more tasty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment