Click to See Complete Forum and Search --> : ~/.bashrc, ~/.bash_profile, ~/.profile, /etc/profile.. how does bash handle 'em?


movEAX_444
08-27-2006, 11:54 PM
I am using Slackware 10.2. When I boot up my PC, it goes to init 3 and then I manually startx (no xdm, etc). I use Bash and Fluxbox. Here are my questions:

1) If I put my settings in ~/.bashrc. Does Bash ONLY read this file or does it ALSO read /etc/profile? (In Slackware I don't have /etc/bashrc)

2) Where would aliases, PS1 prompt, setterm, and 'set' commands go? Can they all be put in ~/.bashrc?

3) If I use ~/.bashrc (I don't have one atm), do I *just* put my own settings or do I have to source /etc/profile? I don't have /etc/bashrc so I won't be sourcing it.

Right now my xset and ulimit commands go into ~/.xinitrc.

I've been having some problems with environmental variables not being set or overwritten so I removed /.bashrc and now I'm starting to edit it from scratch. Thanks for your time.

update: I just read the Bash man page and wrote this. This is correct?

Login shell (AKA virtual terminal AKA interactive login shell):
* Init 1-3.
* ps shows bash prefixed with a '-'.
* When you press Ctrl+Alt+F# and login.
* When you start Bash with the --login option.

Interactive shell:
* When you start a terminal from your window manager.
* ps shows bash as /bin/bash.

If Bash is run as a login shell (i.e, ctrl+alt+F3):
* First it reads and executes /etc/profile
* Then it will read and execute which ever one of these it finds first (in this order): ~/.bash_profile, ~/.bash_login, or ~/.profile.

If Bash is run as an interactive shell (i.e, from your window manager):
* ~/.bashrc is read and executed.

If Bash is being run by a remote shell daemon (SSHd):
* ~/.bashrc is read and executed.


If I got that correct, then /etc/profile will always be execute in my case because I will always boot into a login shell and from there start X and an interactive shell. So for my settings (for example prompt) to apply to all three types of shells, I would have to put the settings in ~/.bashrc and have ~/.bash_profile or ~/.profile just source ~/.bashrc (or make those symlinks), right?

If I just want a minimal functioning .bashrc, can I just put in my own commands and not worry about setting DISPLAY and etc (for example look at the example below. This is what got me confused to begin with)? because by default Slackware doesn't have a ~/.bashrc or ~/.bash_profile.

http://db.ilug-bom.org.in/Documentation/abs-guide/sample-bashrc.html
http://www.digitwebsites.net/BashScripting/sample-bashrc.html

update 2: Heh. OK but I just remembered that in ~/.Xdefaults I set aterm*loginShell to 'true', so every time I start _any_ shell, both /etc/profile AND ~/.bash_profile always get invoked. SO.. I'm concluding that it's safe for me to put my settings in ~/.bash_profile.

I learned my lesson, read the man pages before posting. Sorry :o -- Hopefully this will help others though. I tried to put in as much information as possible.

dr_te_z
08-28-2006, 06:14 AM
http://www.bilbos-stekkie.com/x_shell/x_shell.php

If you need to translate: it's dutch