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
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
This entry was posted on Friday, November 28th, 2008 and is filed under Happy Hacking. You can follow any responses to this entry through RSS 2.0. You can leave a response, or trackback from your own site.
Fusion theme by digitalnature | powered by WordPress
Entries (RSS) and Comments (RSS) ^
Recent Comments