2

I noticed that you can prevent reading /etc/profile by running

bash --noprofile

However this also stops ~/.bash_profile from being read. Can Bash be invoked in such a way as to read ~/.bash_profile but not /etc/profile?

3 Answers 3

1

Try the options --noprofile and --rcfile file_name where file_name is the config file you want read, e.g:

bash --noprofile --rcfile ~/.bash_profile

Well... somebody didn't like this answer, but it appears to be exactly what was desired:

--noprofile causes all normal rc files to not be read.
--rcfile <some file> causes the specified file to be read instead. This can certainly be the user's .bash_profile as requested.

0

You can simply do add in ~/.bashrc file

if [ -f ~/.bash_profile ]; then
        . ~/.bash_profile
fi
0

The login shell will always read /etc/profile, which allows the system admin to set environment variables and paths for all users.

If you are the only user and this is your system you are free to edit or remove /etc/profile if you wish.

1
  • No... --noprofile from the manpage: "Do no read either the system-wide startup file /etc/profile or any of the personal initialization files ..." Commented Feb 18, 2013 at 22:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.