Quote of the Day

May 25, 2018  


The aim of this article is to enable you to add your own customised “Quote of the Day” script. As I use Mutt for emails, I use this to add dunamic signatures to messages while retaining full control over the nature of messages I’m including in my emails.


There is quite a well known linux script called fortune which has some amusing anecdotes. However, many of the messages aren’t really appropriate or of much use beyond mild amusement.

The good news is that it’s really easy to build and maintain your own custom list of fortunes, quotes or anecdotes of the day!

The script

Create a file, let’s call it ~/.local/bin/random_quote, and add the following contents:

#!/usr/bin/env bash

shuf -n 1 $HOME/.quotes.txt

The following is a sample $HOME/.quotes.txt file. Basically there’s a quote for each new line of the file:

"You can use any editor you want, but remember that vi vi vi is the text editor of the beast." - Richard Stallman
"Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without losing something" - Richard Stallman
"If the users don't control the program, the program controls the users. With proprietary software, there is always some entity, the 'owner' of the program, that controls the program and through it, exercies power over its users. A nonfree program is a yoke, an instrument of unjust power." - Richard Stallman

So what this does is take a random line from the file and output it to the terminal.

In the same fashion as fortune you can pass it through cowsay:

$ random_quote | cowsay -f $(ls /usr/share/cows/ | shuf -n 1)

There’s a bonus tip here, which uses the same shuf command to find a random file in the directory /usr/share/cows. As you may have now noticed, shuf randomises a list of items separated with a line separator, and -n 1 takes the first line.

Here’s the result:

/ "The thing with Linux is that the      \
| developers themselves are actually     |
| customers too: that has always been an |
| important part of Linux." - Linus      |
\ Torvalds                               /
  \   ^__^
   \  (oo)\_______        ________
      (__)\       )\/\    |Super |
          ||----W |       |Milker|
          ||    UDDDDDDDDD|______|