2

I want to add a welcome message (and change a greetings row) to Linux.

I added

echo "Hello"
PS1="\u $: "

to “.profile” file, but nothing happens after the reboot. Why?

1
  • 2
    When should this be shown? On the GUI login screen? After logging in from the GUI? On the command line login? Again, before or after logging in? Or maybe when connecting through ssh? Please edit your question and clarify what you are trying to do.
    – terdon
    Feb 23, 2017 at 15:00

4 Answers 4

3

In order to make this work, you need to understand the order and when each config file for shell is being sourced( aka loaded). ~/.profile is sourced at the time of logging in. It will be shown in TTY console perfectly fine - I personally have a message like that in my ~/.profile for when I go into TTY specifically. If you call a shell again from that session, it won't be sourced. Same thing in GUI. You log-in , the file is sourced only once.

My guess is that you are trying to show the message in the GUI terminal. When you log in into desktop your ~/.profile is already sourced, which also means it will not be sourced again in any terminal under that session, and message won't be shown. There's your problem.

The solution would be to place that message at the end of ~/.bashrc. That file is sourced when each interactive session is open, regardless of whether you are logging-in or not.

2
  • I do not know what "sourced" means, but it works!
    – Kosarar
    Feb 23, 2017 at 16:00
  • @user3107513 just means "loaded". Nothing more nothing less :) Feb 23, 2017 at 16:01
2

If you want to get a custom message when you log in via ssh, you need to put a text file in /etc/update-motd.d. Give it a name like 11-my-banner-message and make the permissions -rwxr-xr-x.

The file can look like this

#!/bin/sh
#
#
printf "\n"
printf "   Howdy There!\n"
1

You can do so by simply adding a few lines in the ~/.bashrc file, which would make changes for only the current user for the default shell Bash. Check this out for the full explanation on showing custom-message/ASCII-art/random-one-liner as welcome to the linux terminal.

0

You can write your message freely in a separate file and add

echo "$(</path/to/file)"

in any of the files contained in /etc/update-motd.d

Pretty useful if your message contains " ' or ` chars. (for example in ascii art)

1
  • That's a roundabout way of doing cat /path/to/file
    – muru
    Nov 10, 2021 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .