Jump to content

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


polaryeti

Recommended Posts

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

1/2. What do you mean by "system variable"?
3/4. What do you mean by "alias"?
5. Interactive means you can do stuff, non-interactive means you can't do stuff, and non-login means you can't even log in. Is there something specific about those terms that you think you're missing?

Link to comment
Share on other sites

You won't get one answer because

  • conventions vary by linux distribution
  • can vary by shell
    • bourne shell tends to be a base
      • System scripts do things at boot time and runlevel changes
      • bash is a backwards compatible with sh, but has many extra features
        • Config works with sh/bash/ksh/csh, but anything you do should be bourne shell syntax
      • Other shells have become popular, and are even the default on newer os's (as in OSX now defaulting to zsh)
        • If you're using a newer shell like zsh or fish, then they typically have their own config files you need to research

 

Long story short:

  • Read the /etc/profile script and the /etc/bashrc script.  Often one or both will include scripts in a directory like /etc/profile.d
    • If that is already working, you should place scripts that customize things for all users in that directory rather than modifying the /etc/profile or /etc/bashrc script directly.
  • Individual settings should be done in the user's home directory
    • use ~/.profile or ~/.bashrc
  • Aliases are not part of the bourne shell, so you are utilizing a shell specific extension
    • Bash often supports other files like ~/.bash_aliases

 

As for types of shells:

  • Login shell facilitates login, and will run commands in the files mentioned previously
  • An interactive shell is connected to a tty so that the user can interact with it.  It will also have certain default settings like job control enabled
  • A non-interactive shell is used for scripts, since the user will not be interacting

 

This old serverfault thread provides a good summary of the configuration files loaded.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.