How to display message when starting a terminal

Hello all,

I would like a message to be displayed on the shell when someone opens up the terminal - something like a welcome msg with date and time. I know how to do this by running the shell commands but dont know how to display it when a user opens up the terminal?

Thanks in advance

in your home dir you can find a .profile file.

If not create it

inside the file you can add display for your welcome message using echo or banner

Thanks for your response Amit.

I created the .profile file. But without me executing the file, I want it to display the file contents. Can u pls tell me how I can achieve this? Is there any boot file or something i might have to modify so that I can ask the shell to execute this .profile?

Thanks

when you will login again the .profile will be executed and message will be displayed . Make sure that .profile has the correct permission ro read

I have created welcome.profile in /home and it does have the reqd permissions to read ... i tried to log in again but still it doesnt show my msg :frowning: ... y is that

welcome.profile?? is that your .profilename??? or you changed it??
what have you included in that please post it

I am just a beginner in shell scripting so please forgive me for my mistakes.

Yes, that's the profile name i gave welcome.profile in the dir /home

Code:

echo Welcome to Fedora !!
echo Today is
cal

Please correct me

you should change the name to .profile

mv welcome.profile .profile

Thanks Amit. I changed the profile name to .profile as u said. Now I have /home/.profile

But I logged in again and opened the terminal but it doesnt display the msg i have in .profile. What must b the prob?

Hi,

Put the welcome message in this file /etc/motd.

Thanks,
Alberto

ok do the following steps
1)login
2)vi .profile
3)shift G then press o
4)type banner "message"
5)save :wq
6)exit or ctrl+d
7)login again it should dispaly the message

Thanks to all. Im still not getting the msg.

I use fedora - boots fedora - it asks for password when i click on my login account - after typing the password it comes to the desktop - then i open Applications -> System Tools -> Terminal.

I do not get a msg here when i open the terminal. To log in again, i exit from the terminal by pressing ctrl + d. I click on System->Log out user and then log in again to open the terminal.

This is what I do. To get the welcome msg shud i do something else?

I wanna get atleast this small thing done first .. only then i can proceed to the next level .. so pls help

It will depend on the shell you are using. If you are using bash shell, it may be .bash_profile on your home directory. So include your banner msg in the .bash_profile.

  • Devaraj Takhellambam

Thanks for your response Dev.

First - how do i know which shell i am using?

I renamed the file .profile to .bash_profile. I logged in again but still its not displayed.

echo $SHELL

go to your home direcotory

cd
ls -la 

[ this sould show you the . files]

-Devaraj Takhellambam

Thanks Dev. It displayed /bin/bash which means im using the bash ... But y isnt the msg displayed from .bash_profile? Help needed !!

echo $SHELL

to know which shell.

After making the changes on the .bash_profile on your home directory, did you logout and login again?. Again, as I said, the .bash_profile must be on your home directory.

-Devaraj Takhellambam

no need of logout and login again after changing the .bash_profile just type the below command.

source .bash_profile

Hey thanks!! That works - source .bash_profile prints my msg !! Can u pls tell me something more on 'source'

But i just tried to open another terminal - but the msg is not displayed .. but when i type source _bash.profile the msg is displayed ... how can i get it displayed without typing this each time?