Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] random in bash [Kmail Notification]



Thank you Paul and thank you all for the instructional code and comments 
definitively makes our learning experience here one to remember.

I will copy the script and worked into the kmail command and let you know the 
end result.

Do you need the files wave files?


金曜日 08 3月 2002 09:58、Paul Richter さんは書きました:
> OK, I wrote a bash script that will print one randomly chosen line from a
> specified file.
>
> Eric wanted Kmail to play a randomly picked soundfile every time a mail
> arrived. So, if there's a text file listing all the sound files to choose
> from (filelist.txt), you could call this script 'randline' and do
>
> >$ artsplay `randline filelist.txt`
>
> ----------------------------------------
> #!/bin/bash
> #prints one randomly chosen line from a specified file
>
> INFILE=$1
>
> #all that piping is because wc -l prints formatted output instead
> #  just a single number
> LINECOUNT=`wc -l $INFILE | tr -s ' ' | cut -d ' ' -f 2`
>
> # RANDOM returns 0 - 32767, so normalize it to 1 - LINECOUNT
> let LINENUM=(1+($RANDOM%$LINECOUNT))
>
> head -n $LINENUM $INFILE | tail -n 1
> # end of script
> ----------------------------------------
>
> Paul Richter
> RichterPN@example.com

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links