37

I have been using tcsh for a long time now. But whenever I am searching for something, I often find that the methods specified are bash specific. Even the syntax for the shell scripts is different for the two.

From what I have experienced searching and learning on the internet, bash seems to be the more common shell used. Even the number of questions on this site tagged bash are way more (five times more currently) than the number of questions tagged tcsh.

So, I am wondering whether I should switch to bash. What do you think?

Why should I stick to tcsh OR why should I move over to bash?

Lazer
  • 35,307
  • 3
    I don't think I've ever heard of someone switching to bash; normally people use bash because it's the default and then switch to something better :) – Michael Mrozek Aug 21 '10 at 18:50
  • 6
    @Michael: Well, OS X switched from tcsh to bash in version 10.3, so that's one case of people switching to bash. – sepp2k Aug 21 '10 at 18:54
  • 5
    you should use zsh (which OS X should have switched to) – xenoterracide Aug 21 '10 at 19:01
  • 6
    but write your scripts for dash those should work on just about anything. – xenoterracide Aug 21 '10 at 19:25
  • 2
    I find it somewhat amusing that everyone is suggesting zsh. At the same time it's not amusing because it doesn't really answer the ops question. which is why I made my zsh response a comment not an answer. Straight up though, unless you are having problems learning how to shell script tcsh, go with what you know. If you have problems using tcsh post your problem on here. Don't switch just 'cause. There are more bash posts because it's installed by default in more places, that doesn't make it better. – xenoterracide Aug 21 '10 at 22:19
  • 2
    @xenoterracide I would argue that if you are going to invest the time to learn a new shell, portability is a legitimate consideration, especially if you ever plan on working on machines where you do not have the privileges or ability to install a new shell. I've yet to find a system that has doesn't also have bash or some POSIX compliant sh clone like ksh. – jw013 Jan 24 '12 at 17:58
  • @MichaelMrozek not on FreeBSD –  Feb 07 '13 at 04:17
  • 2
    @ShmuelBrin This is tagged [linux] and [fedora] – Michael Mrozek Feb 07 '13 at 06:04
  • 1
    This is out of topic,... but bash on OSX is stopped at 3.2 due to license issue, and doesn't seem to be upgraded anymore. So I think Apple will change their shell again eventually as like they did with Clang. – Eonil Oct 08 '13 at 04:00

7 Answers7

29

Actually, you should move over to zsh! It's essentially backward-compatible and it's got all the utility of bash with a big huge helping of awesomeness. There's even a book (although I haven't gotten around to reading it).

I will admit to one reason to not use zsh over bash but unless you're constantly working at multiple new installations it doesn't really apply. Especially if you know about the most significant differences. This however is really akin to the differences between vim and vi; you don't want to be naive but practically it's no big deal. Even hardcore vim users can find their way around emacs and vice-versa.

gvkv
  • 2,738
  • 1
    The backwards-compatibility of zsh to bash is not that great. Of course there are obvious things like the ** globbing which simply doesn't exist in bash, but the real issue are the many subtle differences. As a somewhat extreme case, I'd strongly advice against running any bash shell script through zsh (which easily happens if you reuse your bash aliases in zsh, or if you copy&paste commands from tutorials.) – vog Dec 21 '21 at 12:46
26

After learning bash I find that tcsh is a bit of a step backwards. For instance what I could easily do in bash I'm finding it difficult to do in tcsh. My question on tcsh. The Internet support and documentation is also much better for bash and very limited for tcsh. The number of O'Reilly books on bash are great but I have found nothing similar for tcsh.

25

You should switch to a POSIX compliant shell http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html , like one of bash, ksh, dash, but not zsh and certainly not tcsh. It has been a long time since csh was declared a poor choice for scripting: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ , tcsh isn't that much different in that area.

When writing scripts, make sure to use POSIX only constructions (i.e. avoid bashisms and the likes) if you don't want to be locked again in something non portable.

jlliagre
  • 61,204
8

The compatibility obsessed are missing the point, I think. If you try to make everything compatible by putting #!/bin/sh at the top and using .sh extensions, but never test on anything but bash, you haven't guaranteed a compatible script! Better to just use #!/bin/bash and .bash so that users actually know the real requirement.

If you know zsh, tcsh, or something else better than bash, and have a good reference manual for it, don't hold back. Just like people expect to install perl or python to be able to run some scripts, they can handle installing your obscure shell, too! :D

Kevin Cantu
  • 3,794
  • 1
    Actually isn't /bin/sh guaranteed to point to korn-compatible shell while tcsh is csh-derived shell. It is likely that /bin/sh already points to bash or other compatible shell and it is nearly certain it won't be affected by changing of user shell. csh and sh are completly uncompatible. – Maja Piechotka Dec 27 '10 at 18:49
  • 2
    I'm not sure what is guaranteed. I know there are lots of people writing scripts for "/bin/sh" that are littered with Bash-isms which Bash-as-/bin/sh tolerates, but which confuse dash (Debian's ash and Bourne compatible shell). – Kevin Cantu Dec 29 '10 at 02:30
  • Another point: #!/bin/bash will not constrain which version of Bash you were using and there are some incompatibilities from one version to another, although the worst were introduced a long time ago with v2. I don't know of any incompatibilities between versions in POSIX compatibility mode. – Charles Stewart May 16 '11 at 09:36
  • Anyone should feel free to write for whatever shell they want, and you make a valid point in regards to #!/bin/sh alone -ne POSIX. However, being concerned about POSIX compatibility should not be the type of consideration labeled 'obsessed'. Invoking sh defaults dash with debian/ubuntu, and has for a while now. I know that would not qualify as 'guaranteed', but rarely would I consider anything portability 'guaranteed'. I would be even more reserved with a 'shell script'. – J. M. Becker Jan 09 '12 at 07:06
7

Which shell? Go for the one with the best "ease-of-use" vs "hassles" ratio...

If you can't find enough general examples and explanatons for your "Maserati" shell, then it's extra performance may be more of a problem than a bonus...

I found this article/site interesting; it may be worth a read:
UNIX shell differences and how to change your shell

Peter.O
  • 32,916
0

zsh probably has a few more similarities to tcsh than bash does.

See: http://zsh.sourceforge.net/FAQ/zshfaq02.html#l13

People often claim that zsh can do things bash can't, but I have not found that to be the case. What I have seen is that for zsh it is easier, built in or turned on by default, while in bash it is an addon script, has to be turned on, or is more difficult.

(disclaimer: I am a bash user that has sometimes considered switching to zsh)

-3

For some kinds of reasons, I used to tcsh, as I used it than 20 years ago. As I know bash is originated from sh but of course with lots of csh stuff but tcsh is originated from csh. I really like the command completion in the early days but it is available in most shells now. For scripting, shall we stick to /bin/sh?

David
  • 1