first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / core / random_iter.sh
1 #!/bin/bash
2 COMMAND='play -v 10'
3
4 COUNT=$#
5 if [ $COUNT -ne 1 -o ! -d $1 ]; then
6         echo random_iter needs a directory name where the files to be randomly
7         echo chosen from are located.
8         \exit 0
9 fi
10
11 NUMBER_OF_FILES=$(ls -1 $1/* | wc | awk '{ print $1; }')
12
13 if [ $NUMBER_OF_FILES -lt 1 ]; then
14         echo There are no files in $1.
15         \exit 0
16 fi
17
18 RANDOM_CHOICE=$(expr $RANDOM % $NUMBER_OF_FILES + 1)
19 CURRENT_PLACE=1
20 for i in $1/*; do
21   if [ $CURRENT_PLACE = $RANDOM_CHOICE ]; then
22     $COMMAND $i
23     \exit 0
24   fi
25   CURRENT_PLACE=$(expr $CURRENT_PLACE + 1)
26 done