I really don't know what I'm doing here (my experience in shell scripting amounts to about two hours), but I put together this little script that will print out a random message each time you open a new bash window. Just copy this into your user's .bash_profile file, located in your user's home directory:

Set the fn variable in the first line to the path and name of your quotes file. Each quote should be on its own line, with no extra lines between the quotes.

[robg adds: This worked for me -- note that this will not replace Terminal's welcome message (Welcome to Darwin!) with the quote -- it shows up after the welcome message. If you want to change the welcome message, you need to edit /etc/motd. Replacing the welcome message with a random quotation is left as an exercise for the reader (i.e. I don't have a clue...), but this hint might get you started.]

Hint Options

Click here to return to the 'Show a random message at bash shell startup' hint

The following comments are owned by whoever posted them. This site is not responsible for what they say.

Show a random message at bash shell startup
Authored by: mankoff on May 14, '07 07:37:01AM

This script is nice and all, but why re-invent the wheel? The 'fortune' program has been around since 1979, so I'm guessing they've fixed any bugs and implemented almost all the major features during the past 30 years. Why not just use fortune and your own custom fortune file?

You can go even more environment friendlier, than that ... :-) No need for sed if you already start awk ... and no need to read the file twice.awk "{ lines[NR] = $0 } END { print lines[$RANDOM % NR + 1] }" /path/to/quotes.txt

And if you're interested in various other solutions (eg. Perl :-) ), then check out this thread.

Of course one should choose the solution that suites her/him better ... eg. if you've got a quotes.txt of some GB in size, then caching the lines in an array might make your os swap a little bit ... ;-)

Back in the olden days, we used to have /usr/bin/fortune to do just this. This program was put into our .profile or .login to print right before the prompt. It was a single program that would read a specific file, usually /usr/lib/fortunes, and/or ~/.fortunes. There was even an "obscene" mode (-o) that would include those fortunes that were considered obscene in the mix.

I found an open source version of /usr/bin/fortunehere. Using this program may be easier than a shell/awk/perl/php/etc script!