Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
    
No... --noprofile from the manpage: "Do no read either the system-wide startup file /etc/profile or any of the personal initialization files ..." –  SuperMagic Feb 18 '13 at 22:55
add comment

You can simply do add in ~/.bashrc file

if [ -f ~/.bash_profile ]; then
        . ~/.bash_profile
fi
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.