sh[it] and What am I missing here?

Polytropon freebsd at
Sun Jun 5 20:36:35 UTC 2016

On Sun, 5 Jun 2016 16:21:19 -0400, Baho Utot wrote:
> Looks like I need to reread how login/interactive shells are executed as 
> I don't remember when .profiles and .shrc are executed/read

Oh, that's quite simple, if I remember correctly:

For the C shell:
	/etc/csh.cshrc		= global resource for all shells
	/etc/csh.login		= global "auto-exec" for login shells
	/etc/csh.logout		= global "auto-exec" at logout
	~/.cshrc		= user resource for all shells
	~/.login		= user "auto-exec" for login shells
	~/.logout		= user "auto-exec" at logout

In .cshrc, you often find "if ($?prompt) then ... endif" blocks
which make settings apply only for interactive shells (such as
keyboard definitions, history settings or other things that do
not matter for scripting); in such cases, $prompt is set.

For sh:
	/etc/profile		= global resource for interactive shells
	~/.shrc			= global resource for all shells
	~/.profile		= user resource for interactive shells

For bash:
	~/.bashrc		= user resource for all shells
	~/.bash_profile		= same as .profile, but bash-specific

Confusing... I hope I got it right this time. :-)

Note that bash also reads sh's profile files. The files are in
the corresonding shell's language. There also is a precedence in
which order the files are read.

Even though "read" and "execute" means the same for those files,
there are suggestions to use, for example, .cshrc for settings
such as prompt, history, aliases, path, mail ("internal stuff"),
while .login is used to start actual programs, such as biff,
mesg, fortune ("external stuff").

See "man csh", "man sh" and "man bash" for details. They contain
more information about when a shell is considered an interactive
or a login shell.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list