2

I am currently trying to setup some bash definitions (functions, variables) that need to be available for all the users that access a workstation. I have created shell scripts with .sh extension in /etc/profile.d/ directory that have all the necessary. In theory, these should be run once a user logs into the system.

Unfortunately, none of these are available to the users when they use the workstation. The current work-around is to manually source them.

What puzzles me is that these scripts are run when users login remotely via ssh. :|

What am I missing here?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
feverDream
  • 311
  • 1
  • 6
  • 17
  • 1
    Possibly what you're missing is the [Difference between Login Shell and Non-Login Shell?](http://unix.stackexchange.com/questions/38175/difference-between-login-shell-and-non-login-shell) – steeldriver Mar 01 '17 at 01:27
  • Thanks! I was able to get it to work by adding the same definitions to the /etc/bash.bashrc file. Now it works with both login and non-login shells. – feverDream Mar 01 '17 at 22:35

1 Answers1

1

/etc/profile and the files in /etc/profile.d are read by login shells. That's fine for doing things like setting environment variables, which are inherited by child processes: this way they're set in all the programs in the session. It's no good for shell settings such as function definitions, since they're only available in that shell instance. For shell settings, you need to use a shell configuration file instead of a session configuration file. For bash, that's ~/.bashrc, and (on systems where it's enabled) /etc/bash.bashrc.

For more information, see Is there a ".bashrc" equivalent file read by all shells? and Difference between Login Shell and Non-Login Shell?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175