Random fortune cookie

2008/12/04

One of the nicest thing of linux I found at the very beginning of my *nix file was the automatically generated fortune at every login (with slackware).

Well I know it’s not the most important thing for an operating system but it puts me in a good mood to start working in my favorite shell.
Another nice program is cowsay , a funny cows (but not only) that tells you something.

Putting them together you can have a random ascii-animal which tells you a random famous sentence!

Just set your correct COWFILES directory and put it somewhere ;)

COWFILES="/opt/local/share/cowsay/cows"
NFILE=$(ls -l $COWFILES | wc -l)
NUM=$(jot -r 1 1 $NFILE)
COW=$(find $COWFILES -iname '*.cow' -print | sed -n "$NUM p")

fortune | cowsay -f "$COW"

If on your system you don’t have jot then you can obtain the random number line also in this way:

NUM=$(($RANDOM % $NFILE))

Read the rest of this entry »


Follow

Get every new post delivered to your Inbox.