What is /.cshrc For, and what is the diff between tcsh and csh ?

Hello
I'm somewhat new to FreeBSD...
I see that there is /.cshrc & /etc/.cshrc & /username/.cshrc and also I recently created /etc/csh.cshrc but have not created /etc/csh.login - there are so many csh files, scattered about it seems.
Best I can gather is that;
/.cshrc is only an example and not used for anything
/etc/csh.login is only used during logins for csh users
/etc/csh.cshrc is used by anyone who starts a csh at any time
/username/.cshrc is the users chs settings which is looked at last
Isn't there another, /etc/defaults/etc/ too ?
 
There is no difference between the two, in the FreeBSD:
ls -li /bin/csh /bin/tcsh
and you will get the same inode.
csh/tcsh is rather peculiar, isn't it? and therefore I use POSIX sh() everywhere (i.e., interactive shell and scripting).
set -o vi
 
I see that there is /.cshrc & /etc/.cshrc & /username/.cshrc and also I recently created /etc/csh.cshrc but have not created /etc/csh.login - there are so many csh files, scattered about it seems.

I'm going to give my answers inline with what you wrote (which is in italics):
  • /.cshrc is only an example and not used for anything
    I actually don't know why that thing exists, but then, I'm not a csh user. I think it is not used, but I'm not sure. It is identical to /root/.cshrc, in the following sense: both file names are hard links to the same inode, so they are guaranteed to be identical.
  • /root/.cshrc is the setup file used by the user named "root" when they log in.
  • /etc/csh.login is only used during logins for csh users
    Correct. It is executed before ~/.login
  • /etc/csh.cshrc is used by anyone who starts a csh at any time
    Also correct, and also executed before ~/.tcshrc or ~/.cshrc.
  • /username/.cshrc is the user's csh settings which is looked at last
    No, not quite correct: that file is in ~/.cshrc. But you are right, it is looked at last.
  • There is also a file ~/.login, which is read only when logging in.
  • Isn't there another, /etc/defaults/etc/ too ?
    No, /etc/defaults has nothing to do with cshrc and login. It has default versions of rc.conf and such system-wide configuration files.
  • There is another copy of .cshrc and .login in /usr/share/skel. This is what gets copied to the home directory of a newly created user. Actually to be honest, it is not called .cshrc, but instead dot.cshrc, and the program that creates new users (I can never remember whether it's called useradd or adduser) knows how to copy it and remove the word "dot". The sys admin can override files from /usr/share/skel by putting extra copies in /etc/skel.
There is no difference between the two, in the FreeBSD:
ls -li /bin/csh /bin/tcsh
and you will get the same inode.
Yes and no. They are the same inode, the same executable. BUT: If tcsh is started as csh (it looks at argv[0]), then it will act like csh, and turn the tcsh extensions off (more or less). Similarly, the various sh derivatives like bash will also go back to a /bin/sh-compatible mode if started as sh (again, more or less, there are many stories of subtle incompatibilities).

Whether to use (t)csh or (b)(k)(ba)sh is a question of personal taste. These days, most shells are available on most operating systems that are still in mass production, so compability has stopped mattering.
 
  • Like
Reactions: a6h
Rtfm lol. The man files will tell you when and in which order the shell processes these files.

E.g. tcsh()
Startup and shutdown
A login shell begins by executing commands from the system files
/etc/csh.cshrc and /etc/csh.login. It then executes commands from
files in the user's home directory: first ~/.tcshrc (+) or, if ~/.tc-
shrc is not found, ~/.cshrc, then the contents of ~/.history (or the
value of the histfile shell variable) are loaded into memory, then
~/.login, and finally ~/.cshdirs (or the value of the dirsfile shell
variable) (+). The shell may read /etc/csh.login before instead of af-
ter /etc/csh.cshrc, and ~/.login before instead of after ~/.tcshrc or
~/.cshrc and ~/.history, if so compiled; see the version shell vari-
able. (+)

Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on
startup.
 
Back
Top