Comparing interactive Unix shells: bash vs. tcsh

When I started working as a high-energy physicist I was surprised that tcsh was the de facto Unix shell. Hadn't these people seen bash and zsh? Well, no! tcsh is the default shell on e.g. CERN's systems and not many people bother to change. Usually that's a good plan, since collaborations tend to hang their experiment code together via shell scripts written without much concern for issues like cross-shell portability. In fact, using a different shell can sometimes be a good way to find bugs in your software that are nearly invisible in the dominant environment!

If you insist on changing your shell then you'd damn well better understand that you're eschewing help on any shell-specific problems that crop up in your work. So I guess this comparison is only for those who like to go against the grain or, like me, who have got so accustomed to the nicenesses of modern sh-type shells like bash that every moment spent in the presence of tcsh is distilled pain.

I should point out that old prejudices against the csh for scripting purposes don't apply to tcsh: it is just as good as bash for scripting purposes. My preference for bash as argued here is about interactive use, where I think bash has a few genuine advantages.

Well, if still curious about changing your shell from tcsh and you think you'll be able to handle any problems that might arise then here's the few things that I consider make bash a preferable shell to tcsh.

Interactive comments

In both bash and tcsh the # character at the start of a line indicates that that line is a comment and will be ignored. In bash it is also a comment in interactive shell sessions, providing a handy idiom for when you've typed a lengthy command and then realise that you don't want to execute it just yet!

Here's the trick: jump the cursor to the start of the line, type a # and press return: the commented line will be put in the shell history as usual to be retrieved when actually wanted and there's no danger of calling a destructive command too early. I use this all the time... maybe 10-100 times a day! Sadly tcsh has gone out of its way to disable #'s commenting behaviour in interactive shell mode and so the idiom won't work. Bah.

History re-entry

Another nice one from bash: wouldn't it be nice to be able to re-enter a whole sequence of commands in the same order that you did before without having to run up through the history list each time? In bash this is possible with the Ctrl-o keystroke: rather than being given an empty prompt after re-executing a history entry you'll be presented with the next history item: nice!

Oh, even more basic: bash actually remembers the terminal history from your last session. That can be nice to have, since opening a new terminal often provides you with useful entries in the history.

Shell functions

bash provides shell functions as extended alias features: while these can be useful for complex aliases they really come to life for scripts where they make it possible to break the shackles of giant monolithic shell scripts (though you should really look into e.g. Python for genuinely big scripting tasks where robustness is required).

Programmable tab completion

I don't really care about programming the completion modes of the shell myself but it's hard to go back once you've got used to bash completing your CVS commands for you or displaying awareness of what file types LaTeX, XDVI and gv will handle!

A final red-herring is tcsh's apparently half-witted tab-completion behaviour out of the box: it will only display the possible completions when there is only one unless you have the wherewithal to whack Ctrl-d at regular intervals. I object to hitting that key combination unless I'm planning on exiting the shell! However, this can be easily fixed so it's not a real complaint but as out of the box behaviour goes, it sucks.

Well, that's all I've got time and whinging for right now: I hope it was helpful in making an informed decision about whether to leap headlong into the green fields of bash and friends :-) Please criticise what I've written if it's factually wrong on the tcsh side: I don't spend much time there but giving it a fair trial is the least I can do!