Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I wish to display a cowsay message in every terminal window. The command I use is

 fortune | cowsay

Any ideas how to make it appear whenever I start a new terminal session?

share|improve this question

5 Answers 5

up vote 22 down vote accepted
  • Open the file ~/.bashrc (or /etc/bash.bashrc if it should work globally for all users).

  • Add the following at the bottom of the file:

    if [ -x /usr/games/cowsay -a -x /usr/games/fortune ]; then
        fortune | cowsay
    fi
    
share|improve this answer
1  
does the -x flag mean "if exists" ? –  theTuxRacer Dec 6 '10 at 16:58
2  
Yes, "-x" tests if that file exists and is executable. For more information on the the test program see its man page: man test ([ ... ] is short for test ...). –  htorque Dec 6 '10 at 17:03

BONUS: If you're using bash you can make a ~/.bash_logout file and it will execute that when you log out. Make sure to have it sleep for a second or so, or you'll never see it.

cowsay "See you later"; sleep 1

share|improve this answer
    
wow, thats neat! Ill do it immediately! –  theTuxRacer Jan 24 '11 at 7:54

I would consider setting a limit to the size of the fortune command requested.

fortune -s | cowsay

This will produce at most 160 characters. This is a good size for a greeting, anything more than that and long fortunes will flood your terminal.

share|improve this answer

I use

fortune | cowsay -f `ls -1 /usr/share/cowsay/cows/ | sort -R | head -1` -n

This will display a random fortune using a random 'cow'. There's probably a better way to get a random 'cow', but this works for me just fine.

share|improve this answer

Better you use .bash_profile because .bashrc is also executed at commands like scp and they will fail silently if there is any output

I found a nice script on pastebin. currently using it.

http://pastebin.com/f0QXTPbt

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.