I'm trying to write a simple shell script which takes in a list of
arguments and then picks one randomly and spits it out.
In otherwords, if you run:
./random.sh Hello World How Are You
You will sometimes get the word "Hello", sometimes "You", sometimes "How", etc.
Picking the random number is pretty simple:
PICK=`expr $RANDOM % $#`
(pick an entirely random number, and then MOD it by the number of arguments
sent to the program, thus getting a number between 0 and num_args - 1)
My problem is being able to spit out an arbitrary argument.
In otherwords, if "$PICK" is 3, I want to spit out $3 (the 3rd.. err 4th?
argument sent to the program)
I've tried things like:
echo $$PICK
echo $($PICK)
echo ${$PICK}
and so forth...
Before I bang my head over the man pages for bash, I thought I'd just
ask and see if anyone here could give me the magic incantation. ;)
Thanks!
-bill!