Re: [vox-tech] bash question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox-tech] bash question
- Subject: Re: [vox-tech] bash question
- From: "Stephen M. Helms" <mytho_x@pacbell.neMAPSt>
- Date: Mon, 16 Apr 2001 12:47:00 -0700
- References: 200104161951.f3GJp2b19720@sonic.net
Hi Bill,
Try
echo $PICK
William Kendrick wrote:
> 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!
>
>
|