f4f1 bash setup - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Base System > General

General General questions about the FreeBSD operating system. Ask here if your question does not fit elsewhere.

Reply
 
Thread Tools Display Modes
  #1  
Old March 7th, 2009, 21:06
ph0enix ph0enix is offline
Member
 
Join Date: Mar 2009
Posts: 232
Thanks: 117
Thanked 3 Times in 3 Posts
Default bash setup

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.
Reply With Quote
  #2  
Old March 7th, 2009, 21:12
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Administrator
 
Join Date: Nov 2008
Location: Rotterdam, the Netherlands
Posts: 9,849
Thanks: 30
Thanked 1,891 Times in 1,335 Posts
Default

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.
Reply With Quote
The Following User Says Thank You to DutchDaemon For This Useful Post:
ph0enix (March 7th, 2009)
  #3  
Old March 7th, 2009, 21:26
ph0enix ph0enix is offline
Member
 
Join Date: Mar 2009
Posts: 232
Thanks: 117
Thanked 3 Times in 3 Posts
Default

So is there a way to have it process .bashrc at login? It's doing it for root - just not any other users.
Reply With Quote
  #4  
Old March 7th, 2009, 21:34
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Administrator
 
Join Date: Nov 2008
Location: Rotterdam, the Netherlands
Posts: 9,849
Thanks: 30
Thanked 1,891 Times in 1,335 Posts
Default

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).
Reply With Quote
The Following User Says Thank You to DutchDaemon For This Useful Post:
mraj (September 16th, 2009)
  #5  
Old March 7th, 2009, 21:50
ph0enix ph0enix is offline
Member
 
Join Date: Mar 2009
Posts: 232
Thanks: 117
Thanked 3 Times in 3 Posts
Default

Ah, that did the trick (.bash_profile). Yes, I was su'ing to root. You're probably right about it being an interactive shell.
Reply With Quote
  #6  
Old March 8th, 2009, 04:17
keramida@'s Avatar
keramida@ keramida@ is offline
FreeBSD Developer
 
Join Date: Feb 2008
Location: Patras, Greece
Posts: 21
Thanks: 0
Thanked 6 Times in 5 Posts
Default

Quote:
Originally Posted by ph0enix View Post
Ah, that did the trick (.bash_profile). Yes, I was su'ing to root. You're probably right about it being an interactive shell.
Of course it is

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
This way I can keep all my settings in .bashrc.

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"
If this runs in a login shell when PATH="/bin:/usr/bin" and then you launch a subshell within the login shell, your PATH will end up being "/bin:/usr/bin:/foo:/foo", with "/foo" duplicated.

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}"
When FOO is already defined the construct ${FOO:-value} expands to its current value. When FOO is undefined, it expands to 'value', so this way you can keep environment settings from any parent process of the shell, but override them with your own defaults if they are unset.

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}"
Reply With Quote
The Following 2 Users Say Thank You to keramida@ For This Useful Post:
atmosx (August 25th, 2012), mraj (September 16th, 2009)
  #7  
Old March 8th, 2009, 05:22
Mel_Flynn Mel_Flynn is offline
Member
 
Join Date: Nov 2008
Location: Drachten, Netherlands
Posts: 379
Thanks: 7
Thanked 74 Times in 57 Posts
Default

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.
Reply With Quote
Reply

Tags
solved

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT +1. The time now is 21:42.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0