How can I make cowsay say something every time I close the terminal?

I want cowsay to print something like "have a nice day" when I close the terminal. I know I have to have some kind of script, but I'm not even sure how to write a script or how to use it once it's written. Any advice?


You could try adding the line:

trap 'cowsay "Have a nice day!"; sleep 1' EXIT

to your .bashrc file.