Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 958  / 2 Years ago, fri, december 31, 2021, 5:37:10

I want to run a shell script (define some environment variables) at the start of every new shell (globally, not for several users).



So I placed my script into the directory /etc/profile.d/, but that works only for login shells. Is there a better place for my script?


More From » bash

 Answers
4

For interactive login shells, as you've found, you can put commands in scripts located inside:



/etc/profile.d/


You can also accomplish that, in a somewhat less desirable way, by editing the global configuration file:



/etc/profile


For bash (which is the default interactive shell), there is a corresponding file where you can put commands to be run by all interactive non-login shells:



/etc/bash.bashrc


Just as /etc/profile.d and /etc/profile correspond to ~/.profile, /etc/bash.bashrc corresponds to ~/.bashrc.



This does not apply to non-interactive shells. But it's rather unlikely that you have commands you want run by non-interactive shells. (Then they would run every time any script was run.)


[#36863] Friday, December 31, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
looweets

Total Points: 52
Total Questions: 114
Total Answers: 111

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
;