Mac GeekeryGet your geek on. |
|
blog advertising is good for you
recent popular content
User login
|
mattk asks: Questiona trivial, dumb, minor nag about /etc/bashrc. if /etc/bashrc says: if [ -n “$PS1” ]; then PS1=’\h:\w \u\$ ‘; fi /etc/bashrc should say: if [ -z “$PS1” ]; then PS1=… right? AnswerSetting $PS1 in your .bash_profile should work just fine. In fact, I’ve just tested it on two Tiger machines and one Panther, and it worked on all. When bash runs, it loads /etc/bashrc first, then your personal dotfiles. If you’re having a problem with it, jump into the forums and post your /etc/bashrc and .bash_profile and maybe someone will be able to tell what you’ve done wrong.
About JC
Author Biography JC is a former Mac Genius and Mac-centric IT worker with a background in print advertising. He earned a reputation as a miracle worker when he saved the day at a new business pitch with the arcane knowledge that Apple’s ADB cables were nothing more than poorly shielded S-Video cables. JC runs the Heroic Efforts Data Recovery Service and writes Ungenius, a tawdry tale of the life and times of a former Mac Genius. You can contact JC via IM or via the contact form. |
For some reason, it seems that a shell opened with Terminal.app is not considered interactive. Going to the Preferences and choosing « /bin/bash -i » as path to the shell seems to force it to read .bashrc
.bash_profile is always read, even on new terminal launches or window opens. the functionality of .bash_profile and .bashrc, while intended for different purposes, are virtually identical.
just put it in .bash_profile and it’ll work every time, whether the terminal is considered “interactive” or not.
Well, no…
If you launch another shell within a terminal windows (by typing ‘bash’ or, more useful, ‘sudo bash’) only /etc/bashrc and .bashrc will be read, in that order, but not .bash_profile or /etc/profile. If you then use ps you will see that the first shell is called with ’-bash’, making it a login shell, whereas your second one is not. The shell within an xterm is also a non-login interactive shell.
GL
The different files do not have anything to do with what you can do, just what’s executed in the different types of shells.
There are two types of shells: the login shell and the basic shell. Both can be interactive, although traditionally the “basic” shell is called non-interactive.
When you start a terminal, generally you get a login shell. When you issue a direct command to ssh (e.g., ssh foo@host ‘cat /proc/cpuinfo’), you get a basic shell.
.profile/.bash_profile are executed in the login shell scenario. This is where you want to put your stuff that requires interactive stuff: e.g., color ls, specialized tab completion, etc.
.bashrc is executed in the other scenario. this is where you will want to put your basic functionality such as shell functions that you commonly call and whatnot.
It is often common for the .bashrc to be sourced in the .bash_profile for this reason. .bashrc is the bare minimum, where .bash_profile is the full glory.
Packages on any unix system that modify your profiles will act this way and it’s important that the separation be respected, because you’ll be surprised how often you /don’t/ have a login shell.