l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2001 Dec 30 17:03

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
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,


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!

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.