f4f1
![]() |
|
|
|
|
|||||||
| General General questions about the FreeBSD operating system. Ask here if your question does not fit elsewhere. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I have some users setup with bash as their default shell. I placed a .bashrc in their home directories but it's not being read when they first login. If they execute bash again, .bashrc gets processed correctly. The funny thing is, that if I change root's default shell to bash, his .bashrc gets processed during login. What gives?
Thanks! J. |
|
#2
|
||||
|
||||
|
bash(1):
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. See FILES for other options. |
| The Following User Says Thank You to DutchDaemon For This Useful Post: | ||
ph0enix (March 7th, 2009) | ||
|
#3
|
|||
|
|||
|
So is there a way to have it process .bashrc at login? It's doing it for root - just not any other users.
|
|
#4
|
||||
|
||||
|
Why not use ~/.bash_profile as suggested? Or /etc/profile if you want identical settings for everybody using bash. By the way: are you su'ing to root? Then it's probably treated as an interactive shell (honouring .bashrc).
|
| The Following User Says Thank You to DutchDaemon For This Useful Post: | ||
mraj (September 16th, 2009) | ||
|
#5
|
|||
|
|||
|
Ah, that did the trick (.bash_profile). Yes, I was su'ing to root. You're probably right about it being an interactive shell.
|
|
#6
|
||||
|
||||
|
Quote:
![]() A trick that I use to have all my settings in both .bash_profile and .bashrc is to write something like this in my .bash_profile file: Code:
# Startup file for login instances of the bash(1) shell. # First of all, run a .bashrc file if it exists. test -f ~/.bashrc && . ~/.bashrc # The following section should be pretty minimal, if present at all. mesg y >/dev/null 2>&1 /usr/bin/true One important detail when your .bash_profile is set up like this is that .bashrc must be idempotent, so that you can launch multiple instances of bash without odd effects. Idempotency in this case means that you should be careful about constructs like: Code:
PATH="$PATH:/foo" Bash includes advanced features like arrays which you can use to write functions like addpath(). This way you can craft a custom .bashrc file that can be loaded multiple times and avoid the duplicate path entry problem. You can even write elaborate checks about when, why and how a path entry is added. Another nice trick to keep in bash notes when you are constructing your .bashrc file in a way that makes it re-loadable is to use conditional variable expansion and assignment as in: Code:
FOO="${FOO:-value}"
I use this, for example, to set BLOCKSIZE, CVSROOT, and TMPDIR in my .bashrc: Code:
BLOCKSIZE="${BLOCKSIZE:-1024}"
CVSROOT="${CVSROOT:-/home/ncvs}""
TMPDIR="${TMPDIR:-/tmp}"
|
|
#7
|
|||
|
|||
|
I only set PATH when it's unset and actually hate it that /usr/share/skel doesn't do so. It negates /etc/login.conf, which is so convenient for shell-independent environment variables.
|
![]() |
| Tags |
| solved |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bash Script Help! | thavinci | Userland Programming & Scripting | 3 | March 6th, 2009 15:39 |
| bash: dir: command not found | megabytemb | Installation and Maintenance of FreeBSD Ports or Packages | 9 | February 13th, 2009 12:46 |
| Apsfilter Printer Setup | xman73 | Howtos & FAQs (Moderated) | 1 | January 14th, 2009 07:17 |
| Jail setup from scratch | CLUBTURBO | General | 15 | December 9th, 2008 17:43 |
| OSS driver setup | Slesarev | System Hardware | 1 | December 1st, 2008 15:48 |