41

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?

Mechanical snail
  • 5,325
  • 3
  • 28
  • 40
theTuxRacer
  • 15,945
  • 22
  • 71
  • 91

6 Answers6

49
  • 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
    
htorque
  • 63,950
  • 40
  • 194
  • 219
8

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

Joey1978
  • 81
  • 2
7

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.

poulter7
  • 223
  • 1
  • 8
4

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.

user418681
  • 41
  • 1
3

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

Schwertspize
  • 133
  • 1
  • 5
0

I am using

cowsay Welcome to Bash Shell in .bashrc.

This will be prompt every time when you open the terminal.

Linuxian
  • 21
  • 1
  • 3