Wednesday, May 1, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 454  / 1 Year ago, wed, december 14, 2022, 7:17:09

Normally, in bash, the answer would be ~/.bashrc or /etc/bash.bashrc. But unfortunately Ubuntu is sourcing these files from ~/.profile and /etc/profile respectively. So, where should I put such commands on Ubuntu?



See also Why is /etc/profile not invoked for non-login shells? if you are not familiar with these files.


More From » command-line

 Answers
2

It appears there is no standard place for such commands on Ubuntu (without modifying behaviour that may be considered standard on Ubuntu). Here is a work-around that I came up with:



Add this to the beginning of /etc/profile:



IS_LOGIN_SHELL=1


Then, in /etc/bash.bashrc or ~/.bashrc test for this variable:



if [ -n "${IS_LOGIN_SHELL-}" ]; then
# Put your commands here
fi


Hopefully the variable name won't collide with anything else and this doesn't change what other parts of Ubuntu may rely on.


[#26840] Thursday, December 15, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fittecanap

Total Points: 322
Total Questions: 100
Total Answers: 105

Location: Israel
Member since Tue, Nov 17, 2020
4 Years ago
;