[ale] Bash question

Danny Cox danscox at mindspring.com
Thu Sep 5 09:25:51 EDT 2002


Joseph,

On Wed, 2002-09-04 at 18:16, Joseph Mugerwa wrote:
> 1. i created a file where to keep all the mails to my
> freinds
> 2 i have kept all the jokes in one file text format
> and every next joke is separeted with =* sign i.e
> 
> =*
> joke n1
> blabla xxxxxxxxxxxxx
> 
> =*
> joke n2
> blabla xxxxxxxxxxxxx
> 
> My intention was to use mail program like this
> mail -s "joke of the day" [read a joke from the file] 
> myfriendsmail at at.home and this would be a diary cron
> job that send a mail to all the address in the address
> file.

	Here's some ideas that'll get you going in the right direction.

	1) use wc to count the # of jokes: 

		NLINES=$(grep '^=\*$' jokefile | wc -l)

	2) use bash's built-in arithmetic plus the $RANDOM var to get a random
joke number:

		(( JOKE = ($RANDOM % $NLINES) + 1 ))

	3) select joke number $JOKE to send.  You could use perl or awk to do
this.  Of course you could probably use perl or awk to do all of this,
but the object was using bash.  With enough masochism, one could use
bash to even select the joke, but it'll be rather ugly!

-- 
kernel, n.: A part of an operating system that preserves the
medieval traditions of sorcery and black art.

Danny


---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list