2
votes

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.

0

13 Answers 13

20
votes

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

5
  • 3
    +1 bash seems to be nearly ubiquitous in my circles (I'm a Linux person)
    – David Z
    May 7, 2009 at 5:52
  • That seems pretty accurate, from what I've seen.
    – Andy White
    May 7, 2009 at 5:53
  • 1
    Or at least something bash-like: sh (for fast shell scripts), dash, etc. A lot of older unixes also use ksh.
    – Mikeage
    May 7, 2009 at 6:07
  • Have seen bash since the Slackware 6 days, and it will probably stay that way for a few more years. Jun 3, 2009 at 19:17
  • 1
    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.
    – kubanczyk
    Aug 22, 2009 at 16:26
5
votes

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).

1
  • 3
    When bash is invoked as sh, it emulates sh so sh scripts will work correctly.
    – codebunny
    Jun 4, 2009 at 12:59
4
votes

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.

2
votes

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.

2
votes

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

1
vote

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 )

1
  • 1
    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). May 7, 2009 at 15:53
1
vote

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.

0
votes

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.

0
votes

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.

0
votes

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.

0
votes

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.

0
votes

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

0
votes

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .