Bash: Choose a random value out of a set


The best scripts are the shortest.
This chooses one of the arguments randomly. $# is the number of arguments

#!/bin/bash
echo ${BASH_ARGV[ $(( $RANDOM % $# )) ]}

Example:

$ bash randomchooser.sh 1 2 3 4 5 6 7 8 9 120
3

  1. No comments yet.
(will not be published)

  1. No trackbacks yet.