Jump to content

Not understanding when to use ~/.bashrc, /etc/profile ,~/.bash_profile or ~/.profile?

shivajikobardan

I've read tidbits of pages from around 10 books, and I can safely say I am even more confused than before. Earlier I'd just set everything in .bashrc file. LOL.

Say I've scenarios like these:

1) I want to set system variables for user "jacky", what should I use?

2) I want to set system variables for all users, what  should I use?

3) I want to set alias for user "jacky", what should I use?

4) I want to set alias for all users, what should I use?

What are interactive/non-interactive login/non-login shells?

I've asked chatgpt but it gave me convoluted reply.  So, it was not very clear.

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, shivajikobardan said:

1) I want to set system variables for user "jacky", what should I use?

3) I want to set alias for user "jacky", what should I use?

For users typically add custom variable/aliases to ~/.profile or relevant .**shell**rc file (ie .bashrc for bash .zshrc for zsh etc)

 

 

4 hours ago, shivajikobardan said:

2) I want to set system variables for all users, what  should I use?

4) I want to set alias for all users, what should I use?

For setting system wide variable/aliases for all users either modify /etc/profile or create a new shell script in /etc/profile.d/

 

Link to comment
Share on other sites

Link to post
Share on other sites

The original unix shell terminal, named "Bourne Shell", launched via `sh`; `bash` extends that, called "Bourne-again shell".

`.profile` is what `sh` looks for. Tbh I had to look this up bc I'd never even heard of `.profile`.

`/etc/.profile` is the system wide profile and affects everyone.

`.bash_profile` is the configuration profile for just the logged-in user

`.bashrc` is the profile used if `bash` is launched in non-login mode

 

So when you launch `bash`, it will first run `/etc/.profile`, then depending on if you invoked `bash` as login or non-login mode, it will run either the `.bash_profile` or the `.bashrc`. If it can't find a `.bash_profile`, it defaults back to `.profile`

This is a signature.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×