May 24, 2008

How-To: Have a Welcome Message Each Time You Open a Shell

Updated: May 24, 2008

First, create a script which will echo the messages you want to be displayed when you open your shell. For example, create the script 'hello_user' with the following content:

#!/bin/bash

clear
echo -ne "Hello, $USER! Today is $(date).\n\n"
cal
echo -ne "System Info: $(uptime)\n\n"
echo -ne "Fortune of the Day:\n"
/usr/games/fortune

The above script welcomes the user, shows the current date and system info, and then prints a random fortune. Next, put this script into a directory, say ~/bin/, and make sure it is in your $PATH. To do that, edit ~/.bashrc and add the following line:

PATH=~/bin:$PATH

This will add the directory ~/bin to your $PATH.

Next, edit ~/.bashrc and add the command which will run your script:

hello_user

And this is it. Next time you'll open a shell, a message which looks like the one below will be displayed:


The idea to make this tutorial came after I read this post on UbuntuForums.

No comments: