I think that csh exists in FreeBSD's base system purely for historic reasons, but it shouldn't actually be used for anything, especially not for scripting.
Well, I definitely disagree with that. I've been using
csh as the root shell for pretty much as long as I used FreeBSD and I think there's a major advantage in doing so.
Csh is fully aimed at interaction. A very good example can be seen above when I used a "for a in..." with
sh an its "foreach a" counterpart in
csh. The latter allows ("softly forces"?) you to cut up all your commands into smaller pieces and provide them one at a time. This makes it much easier to carefully check all your commands to verify that they're really going to do what you intended.
With
sh (and most other bourne-like shells) not so much; when you enter enough commands then the first part of your line will eventually disappear from the screen and that's it.
As to scripting...
If you're curious, ask the search engine of your choice for “
csh programming considered harmful”. ;-)
I read a few posts (I was familiar with some already) but it all boils down to "
It's harmful because it works different than bourne", to which I can only reply "
Well, duh!". I can't help but pick that up as people blaming the tool for its (in)abilities. And then you have plenty of people blindly copying that list of examples (they're not real arguments) as if it somehow holds any value within the context of good vs. bad. Yet it doesn't: it all boils down to
csh behaving different than other shells. There's a solution to that and it's called a manual
And
csh also has plenty of advantages. When I test something then it makes sense to have only stdout ('|')
or stdout + stderr ('|&') because who cares about them separately? An error is nothing without output ('context') and it gets hard to find a problem without errors
Of course that changes when you're scripting.
And well... in the list you can read about an issue with
kill -l `cat foo`
vs.
/bin/kill -l `cat foo`
. It doesn't help that I can't reproduce this on
csh myself, but it gets worse when I notice that other shells behave in pretty much the same uncanny way:
Code:
peter@zefiris:/home/peter $ echo $0
-/usr/local/bin/ksh
peter@zefiris:/home/peter $ kill -l `cat bugzilla.png`
: bad numberin/ksh: kill: PNG
peter@zefiris:/home/peter $ /bin/kill -l `cat bugzilla.png`
usage: kill [-s signal_name] pid ...
kill -l [exit_status]
kill -signal_name pid ...
kill -signal_number pid ...
peter@zefiris:/home/peter $ csh -l
Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ '
-- Mathieu <mathieu@hal.interactionvirtuelle.com>
% kill -l `cat bugzilla.png`
HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP
TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH INFO USR1 USR2 LWP
% /bin/kill -l `cat bugzilla.png`
usage: kill [-s signal_name] pid ...
kill -l [exit_status]
kill -signal_name pid ...
kill -signal_number pid ...
% sh -
$ kill -l `cat bugzilla.png`
usage: kill [-s signal_name] pid ...
kill -l [exit_status]
kill -signal_name pid ...
kill -signal_number pid ...
$ /bin/kill -l `cat bugzilla.png`
usage: kill [-s signal_name] pid ...
kill -l [exit_status]
kill -signal_name pid ...
kill -signal_number pid ...
Each to their own but I'd say that
csh gave the most reasonable response in this scenario
And yes, I realize that the list is most likely dated, but I cannot help but wonder how the other shells behaved back then.
Now, don't get me wrong: I'm definitely not advocating
csh scripting. Simply because I'm already familiar with plenty of those quirks. As I mentioned earlier: csh excels as an interactive tool but it's definitely not the best for scripting,
sh is much more useful. But actually considering it harmful is IMO ridiculous; it's not the tool which causes damage, but the tool that's using it.
Apart from that, if a task grows sufficiently complex that you're forced to play with IFS, eval
and other evil things, you should rather implement it with a more capable scripting or programming language, such as awk, Python or whatever.
That I fully agree with
Still, sometimes for hobby projects it can be fun to take the shell into extremes and still get work done. Also because sometimes (not always) you'll have less overhead when using the shell itself than a full blown scripting language.
Even so... I really need to finally spend more time on learning
awk
Thanks again for your comments!