3

I have run into an issue when executing script in /etc/profile.d/script.sh. On one of my machines (only this one, on the others it is running well), when I do

echo "$BASH_VERSION" >> /home/synek317/log
echo "$SHELL"        >> /home/synek317/log

the result is that BASH_VERSION is empty, but SHELL is /bin/bash. However, when I run terminal and type echo $BASH_VERSION, it is filled correctly.

I run this on Ubuntu 16.04.1.

Do you have any ideas why is this variable empty during execution of /etc/profile.d/ scripts?

5
  • this is fresh copy of ubuntu. It is empty only during login. Commented Oct 3, 2016 at 16:08
  • The only place I found is /usr/sbin/lightdm-session but it is the same on other machine... Commented Oct 3, 2016 at 16:24
  • 4
    SHELL is not necessarily the name of the current shell; it's the name of your login shell. The scripts in /etc/profile.d may be executed by /bin/sh, which is dash in Ubuntu. Commented Oct 3, 2016 at 16:30
  • 1
    Write env, set, $$, pwd, id, "ps -aef" and all such other things in to the file along with BASH_VERSION and SHELL. That should give you clues on what shell executed it and what was its environment like. Commented Oct 3, 2016 at 16:53
  • Thanks for the clues. I have found out that all of this is working, well, accidentally. The line in my profile.d script checks not empty BASH_VERSION or ZSH_VERSION. lightdm-session sets BASH_VERSION as empty var when launching profile scripts. So it means that my profile.d script works only because of ZSH_VERSION is set. Now the question is why on one machine it is set and on the other it is not. It is weird however. Commented Oct 3, 2016 at 17:06

1 Answer 1

1

By definition, /etc/profile.d scripts are not run by Bash.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer is correct, but may leave you wondering who reads those scripts. See unix.stackexchange.com/questions/462663/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.