We have CENTOS 7.x Linux with bash shell. I need a some environment variables to be set and some messages involving these env vars to be echoed (a banner kind of thing, but dynamic because it's got these env vars) for all users when they login or open an xterm/konsole. I've set this up in /etc/profile.d/somescript.sh

I see that when I log in, the env vars are indeed set, but the echoing doesn't happen. Why is that?

I see code in /etc/profile that reads like:

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
            . "$i" >/dev/null

Is it because of the output redirection above in the else branch? Or possibly some other script in the hierarchy of startup scripts that clear the screen? Or something else? How do I resolve this?

1 Answer 1


If there is no reason to NOT use a motd banner, this answer on Server Fault from Læti might help you; namely:

/etc/motd is only read and not executed, so technically speaking, you cannot put shell commands in there.

However, it's possible to execute a shell script at login time that will have the same result. This is usually achieved by adapting the /etc/profile script that is executed each time a user logs in. A useful practice is to put the command you want to be executed in a script named /etc/motd.sh and call this script from /etc/profile, usually at about the end of it.

  • My bad. motd.sh works fine
    – vharihar
    Commented Apr 4, 2022 at 14:34

You must log in to answer this question.

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