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



## mikey777 (May 11, 2020)

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 ?


----------



## a6h (May 12, 2020)

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`


----------



## ralphbsz (May 12, 2020)

mikey777 said:


> 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.



vigole said:


> 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.


----------



## SirDice (May 12, 2020)

ralphbsz said:


> I actually don't know why that thing exists, but then, I'm not a csh user.


It stems from a time when root's home directory was / and /root didn't exist.


----------



## George (May 12, 2020)

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-_
> ...


----------

