Stop Using (and Teaching) C-Shell and Tcsh
Last Updated: 01-October-2007
You should stop using, learning and teaching C-Shell and its extended Tcsh implementation, because of their horrible, inconsistent syntax, lack of usability and the fact that they induce bad habits. The reasons for that are:
-
Tom Christiansen (of Perl fame) wrote Csh Considered Harmful, which gives many good arguments for csh's inadequacy as a shell scripting language. Bruce Barnett's "Top Ten Reasons not to use the C shell" gives more convincing arguments, and illustrates how awful csh is.
-
Bash has real functions (as well as aliases) instead of just aliases, that are easy to break.
-
Bash has proper quoting. Handling whitespace in csh is painful. I once witnessed a pair of Technion students get bogged down writing the solution for a homework exercise, because they wanted their C-Shell script to handle whitespaces properly. I later tried the same with bash, and it was trivial to do.
-
- Bash is the default scripting and login shell on Linux.
- ksh - the Korn Shell, a Bourne-shell derivative, is the default login and scripting shell on non-GNU System V systems.
- On recent version of Mac OS X, bash is the default scripting and login shell.
- Only on the Open Source BSD variants, ash (a slightly enhanced Bourne shell implementation) is the scripting shell and tcsh is the default login shell.
- On cygwin the default shell is bash. zsh is available for either cygwin or for non-cygwinned win32.
In all cases, C-Shell is not used for scripting at all, only perhaps for interactive use. And Bash/ksh/zsh is now often used for both.
-
Entire Bash mini-programs can be written, tested and debugged in one line. This is impossible to do in csh which forces loops to be on separate lines.
-
Sub-shells and capture-subshells ($(...)) actually work in Bourne Shell. And Bash actually has capture-subshells which are much safer than back-ticks (`...`).
-
The students tend to conclude that C-shell is "The UNIX Shell". Seeing how lame C-shell is they tend to believe that the UNIX shell sucks. Which is not the case for Bash and friends which are beautiful and a joy to work with.
-
The wrong legacy reasons: many institutions once thought they had to make a choice between the Bourne shell, sh, which had a sane syntax and programmability but bad for interactive use, and tcsh which had bad programmability but with good interactive capabilities.
For this generation the choice is clear: bash or zsh that combine both good programmability and good interactive use. There's no reason to keep using tcsh forever.
Alternatives
Instead you should use, learn and teach one of the following shells:
- GNU Bash - the Bourne-Again-Shell - an extended Bourne-shell-compatible shell, with good usability. Great for both interactive use and scripting. The default shell on many systems.
- Zsh - the Z-shell - the Emacs of shells: a shell that has everything, including the kitchen sink. Also Bourne-shell derived.
There's also The Korn Shell which has lately been open-sourced, but I have never really tried it. It should be a very decent shell, though.
For academic teaching I suggest teaching the common base of these shells, possibly with some bash extensions.
Links
- A Linux-IL thread with many comments
- A thread in the Haifa Linux Club mailing list with some comments