Friday, January 28, 2011

Most common Unix/Linux shell

This question might be a little naive, but is there one shell that tends to be the most popular among Unix/Linux users?

My previous company was basically standardized on tcsh, so I learned that one for-better-or-worse, but I'm wondering if I should learn bash, ksh, or any other, if those tend to be more common.

  • For Linux i'd say bash, while I see that classical Unix variants seem to prefer csh.

    David Zaslavsky : +1 bash seems to be nearly ubiquitous in my circles (I'm a Linux person)
    Andy White : That seems pretty accurate, from what I've seen.
    Mikeage : Or at least something bash-like: sh (for fast shell scripts), dash, etc. A lot of older unixes also use ksh.
    Avery Payne : Have seen bash since the Slackware 6 days, and it will probably stay that way for a few more years.
    kubanczyk : Wait the minute... csh? You wanted to say that classical Unix variants seem to prefer ksh, right? AIX, Solaris, HP-UX. For what I know csh has been abandoned a decade ago, except for *BSDs that still stick to tcsh.
  • Mac OS X switched from tcsh to bash as the default login shell around the 10.3 release. Solaris tends to default to sh for root and csh for regular users.

    From Graham Lee
  • Since I want my scripts to run on all systems I want (well, as many as possible), I write and test my scripts with Bourne Shell (/bin/sh) which is present in all Unix systems I ever met.

    Just need to be aware that on some systems /bin/sh is in fact bash (ex: my Mac).

    codebunny : When bash is invoked as sh, it emulates sh so sh scripts will work correctly.
    From chburd
  • Learn sh as your primary shell

    As a result your scripts will also work in bash

    there is also..

    zsh

    ksh

    tcsh

    But to be honest most linux distros link sh to bash ( as its its most popular superset )

    Brian Campbell : Er... csh is not compatible with bash. No one links csh to bash. tcsh is the most common variant of csh, and csh may be linked to tcsh. Many systems link /bin/sh to bash, but some link it to dash (and I think that a few have linked it to zsh).
    i-moan : indeed you are right. thank you :)
    From i-moan
  • I guess I'm a "classical UNIX variant" (from Michael Stum's answer) kind of guy as I use tcsh although I run Scientific (rebranded RHEL like CentOs) and Ubuntu Linux.

    This stems from the fact that some of the software I used when first getting into Linux (and still use) was designed to run under csh and didn't always play nicely with sh/bash. So that's what I learned and I've just stuck with it. The first thing I do when setting up a new account is switch my default shell to tcsh.

    While I can use bash without a problem, the syntax isn't the same between the two shell types (contrary to i-moan's comment) and I actually prefer the tcsh syntax although I believe it is a bit more limited. I don't do all that much shell scripting so I've never had an issue.

    That being said, I agree, like the other commenters, that bash is the most popular, possibly because it has been the default for a long time and people don't generally bother switching from the default as was mentioned by David in the Comparison of Unix Shells question

    From dagorym
  • Use the shell you're most comfortable with, but you should be familiar with the others and their basic operations. I know that Oracle (or at least Oracle DBA's I've known) tends to do things using ksh, while a lot of other scripts (like installers) are run in sh.

    The nice thing is that most distros (linux or other *nix variant) have many of the shells available, so you can still run scripts in shells other than your logged in shell.

    True sh appears to be going away in favor of bash, as Linux has made bash a much more popular shell for working than sh (at least for those "classical UNIX variants".

    I'm currently forcing myself to run in zsh to learn more about it (have usually run bash or tcsh in the past). Then I'll toy with ksh, though I tried that once and really didn't like it.

    From Milner
  • Certainly bash is pretty popular amongst Linux distros - but if you're aiming to be a cross UNIX admin, I think KSH is the one to go with. Wherever I've worked that runs multiple flavours of UNIX, it's the default. It's slightly less broken than the original Bourne Shell, but it hasn't introduced its own features which aren't POSIX compliant (like bash, csh or tcsh did).

    Indeed, this is the reason that the debian based distros now tend to link /bin/sh to dash now - as that is POSIX compliant, and also a lot less memory hungry than bash. Unfortunately a lot shell scripts written for linux distros over the years which say #!/bin/sh on the shebang line actually assume bash is the shell, and use features which are only available in bash - not good practise.

    Bash is good end user shell, but I would argue its large memory footprint makes it less than ideal for shell scripts.

    From GodEater
  • The most popular is bash. The best is zsh, but it's not so much better than bash to convince many people to change their habits.

    Using csh or sh is a mistake. You should only use ksh if you're forced to (bash is not available). If a script must have good portability, either use sh and be aware of what features are unique to your implementation, or consider bash as it's quite widespread.

    I have seen people who are significantly more comfortable with tcsh to prefer it over bash.

    I think it makes sense to habitually use the same shell for interactive use as for scripts. I recommend zsh to people who are newly learning and who have control over their environment, but bash to people who are already slightly comfortable with it. People who may have old shells forced on them or be forced to maintain old scripts should get comfortable with sh, csh, and ksh.

    My comments come from the bias of someone who uses bash regularly, occasionally notices zsh, says "that's cute" and goes back to bash, and who resents being occasionally forced to use sh or csh due to legacy "requirements".

    Note that when I say sh, I mean the old bourne shell, and when I say csh, I mean the old csh. Sometimes these are links to more modern shells.

    Also beware that there are two major releases of ksh out there, with some significant differences in feature sets.

    From carlito
  • It's perl.

    I always find perl even on some old solaris 2.6 and writing perl is far more portable than writing shell script, keeping in mind that /bin/sh may vary a lot. Then instead of writing some csh/ksh/bash, where i'll always find one server with the wrong version of the shell for feature X, i've switched to perl. It's sometimes a bit more verbose, but i get 100% portability for my work.

    And no need to say that a shell itself does nothing: if you don't have to correct grep/awk/sed versions (and there are dozens of awk implementations), you're screwed, while perl pattern matching, data structures, etc are universal.

    From BenoƮt
  • I'm working with a lot of AIX servers with ksh. It is also the default shell for root in OpenBSD.

    Each time it is possible, I switch the default shell of my user account to zsh.

    I write sh or perl scripts as often as possible.

    From Benoit
  • I'm relatively new in Linux (I've been working with it for about two years). And I think most modern distro's use bash.

    Though I've heard good things about ZSH and it's backwards compatible with BASH

    Check out this link: It gives a good overview of advantages of ZSH over BASH

    From Hofa
  • I would recommend against using 'tcsh' as a shell. It tends to make you think that writing shell scripts in tcsh is ok. It's not.

    The real attraction seems to be the 'up-arrow' command line ease-of-use, but with bash you get that anyway.

    Also, coding scripts is much easier in 'sh' and it's derivatives (like bash and ksh)rather than csh and tcsh. I've also found that sh is on ever flavor of unix, and bash is easily obtainable as a first choice add-on.

    I'd warn against using the features of ksh and bash (like variable arrays and hashs) unless you can guarantee it's existance throughout the enterprise.

    From ericslaw
  • Bash is one of the most popular shells IME.

    If you want to write portable shell scripts use /bin/sh, which is a very small shell. It doesn't have all the features that bash has. Some linux distros have /bin/sh symlinked to /bin/bash, so be careful if you're writing a shell. Ubuntu has /bin/sh symlinked to /bin/dash, which only implements all the /bin/sh stuff. If it works on /bin/dash, then it'll work on sh.

0 comments:

Post a Comment