59

I've used bash, csh, and tcsh. But I asked this question, and Jonathan informed me that csh isn't to be trusted. So what Linux shell is good for development. and why?

Csa77
  • 649
  • 13
  • 19
Scottie T
  • 11,729
  • 10
  • 45
  • 59
  • 1
    OK - your call. But...which shell did you decide to use? I think that should indicate the answer you accept; it will be understood by all that there is an element of subjectiveness in that decision since shells are like editors - different people like different ones. – Jonathan Leffler Feb 26 '10 at 18:56
  • 2
    If anyone wonders what shell I chose after asking this question, I switched to bash, but mostly because I switched companies. Occasionally I work on the program that I was on at my old company, and I have to switch back to csh or tcsh because that's what they're set up to use and it's not worth the cost to rewrite the environment. – Scottie T Apr 09 '10 at 19:50

19 Answers19

64

The most common shell, by far, on Linux is bash. Unless you have a good reason to use an alternative, I'd suggest that sticking with bash, or the most commonly used shell by your project team (or that the bulk of the shell scripts you have to work with) uses.

The only other very common contender is dash, which is becoming more widely used by the Ubuntu project.

This really is personal preference, well, except for csh.

Wikipedia link for csh

Ojasvi Monga
  • 4,437
  • 2
  • 18
  • 35
Kyle Burton
  • 26,788
  • 9
  • 50
  • 60
  • 1
    Link to `csh` no longer works, but this one does: http://www.grymoire.com/unix/CshTop10.txt – arielf Jan 28 '19 at 19:44
63

I prefer zsh.

The tab-completion alone is worth it:

  • It expands wildcards if you want(handy when you want to delete all but one file in a directory)
  • Will give you a list of switches after specifying a program
  • Gives tab completion options below the line you're working on, which is pretty handy.

http://zsh.sourceforge.net/

SomeDork
  • 639
  • 4
  • 2
  • Pardon my ignorance but how does it list the switches of an executable? Does this only work for commonly used programs such as ls, ps,.. or for any given program? – utku_karatas Nov 24 '08 at 04:47
  • I imagine that it parses the man pages? Can't say for sure though I don't use the zsh though I might take a look after this endorsement. – Tabitha Feb 03 '09 at 09:25
  • It might run programname --help in the background. – Joshua Feb 27 '09 at 21:32
  • Is fizsh (Friendly Interactive ZSHell) still actively developed/used, and how does fish compare to fizsh? I see fizsh is available on Ubuntu. I'm thinking about installing it. – MountainX Mar 29 '12 at 17:31
  • A bit late, but zsh has a set of completion scripts that it consults for completion information. Completion scripts for a number of common applications are included with zsh and some applications provide their own. –  May 27 '13 at 20:38
  • @MountainX, once you install ZSH and start maybe as first configuration with [OhMyZsh](http://ohmyz.sh) - Fish scripts would feel obsolete. – leonardo Sep 25 '15 at 06:14
29

For interactivity, use Zsh. For a while I was the maintainer of the FreeBSD port of the Bash tab-completion scripts, but abandoned it as soon as I tried Zsh for the first time. It can do everything Bash can do but more easily and more elegantly. It also has the nice property of having extremely Bash-like keystrokes, so if you're on a system without Zsh, you'll be able to make do (even if it wouldn't "feel" as nice).

For scripting, use Bourne Shell (sh). It's the POSIX standard scripting language and your scripts are pretty much guaranteed to work everywhere. Bash and Zsh and other shells have nice extensions that you'll miss but those tie you to a specific setup. Ignore that advice for personal-use-only scripts that you're certain you'll never run elsewhere, but remember that it's a real tradeoff that you need to consider.

But in summary, Zsh. I don't know of anyone who's tried it who didn't immediately and permanently switch. It really is that good.

Kirk Strauser
  • 30,189
  • 5
  • 49
  • 65
  • "For a while I was the maintainer of the FreeBSD port of the Bash tab-completion scripts, but abandoned it as soon as I tried Zsh for the first time. " That is, uh...telling. I keep meaning to spend more time with zsh, but I've got enough Bash custom configuration that I'd need to spend some time rewriting it for zsh conformance. – Kyle Strand Dec 15 '15 at 22:42
  • "It can do everything Bash can do" Please show how you do this (replace \n with an actual newline): bash -c 'shopt -s expand_aliases 2>/dev/null;alias eecho=echo;\neecho foo' – Ole Tange Mar 25 '16 at 19:53
  • What's the goal of that? – Kirk Strauser Mar 25 '16 at 20:48
26

Fish (Friendly Interactive Shell) is a nice alternative to most of the other shells. It has a consistent syntax, nice tab completion and syntax highlighting, is easy to pickup and use (especially if you don't have habits from other shells), and has excellent runtime help.

Downside is that it's erratically developed, has a small (but helpful) user base, and is very different than other shells. Backwards compatibility with shell idioms was not a priority.

In many cases this is good... a lot of the standard shells have really stupid ways of doing things, just because it's always been done that way. "do/done", "case/esac", "if/fi"? This is insanity that fish does away with.

It's worth a look.

Rhubbarb
  • 4,248
  • 6
  • 36
  • 40
Myrddin Emrys
  • 42,126
  • 11
  • 38
  • 51
  • 3
    There are lots of small little change which make you more productive with it. The permanent background auto-completion is great for example, it gives you previous command when you didn't even remember you had typed them once. – Florent Feb 11 '14 at 20:37
18

Since I believe I'm the person who suggested that you should use something other than C Shell, perhaps I should should qualify my remarks slightly, and then support those who said 'bash on Linux, Korn shell on other platforms (unless bash is installed there too)'.

Rather like editors (do you prefer vim or emacs), choice of shell is partly a question of familiarity and partly a question of preference. There are many who like C shell, though I do believe that it is less easily programmable than Bourne shell and derivatives. What I have in my .cshrc is, indeed, equivalent to exec /bin/ksh (it isn't identically that because I want to execute a login shell - one that reads the profile and so on), but I wouldn't condemn anyone for using C shell or a derivative if it is an informed decision.

If you decide that you want to use something other than C shell, then you are basically in the Bourne shell camp, for which the POSIX standard more or less specifies the expected behaviour and then the different shells -- that is, the Bourne, Korn or Born Again shells -- add (or, in the case of the classic Bourne shell, subtract) a few features. If your code might ever need to move off Linux to HP-UX, Solaris or AIX (the surviving trio of the classic, AT&T-derived Unix variants), then you should consider ensuring you write your shell scripts in classic Bourne shell, though Korn shell is also pretty safe. Note, though, that on Linux you can write #!/bin/sh and get Bash, on the other platforms, you will get Bourne shell.

I switch between Korn shell and Bash without major problems - and seldom with minor problems. I tend to stay clear of those corners of either language that are not well defined - which tends to mean 'defined in both'. Another problem for those using Linux is that the GNU tools have more options than the classic Unix versions, and you can lose portability not because of the shell programming constructs that you use but because of the command options you use. Experience and ready access to the manual pages of other systems helps enormously.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
8

I usually stick to bash, because it's more friendly than straight-up sh, and it's the default on every distro I've used semi-regularly (SuSE, RHEL, Ubuntu, Slackware).

If you're planning to write portable shell scripts, however, make sure they all run in real sh.

warren
  • 32,620
  • 21
  • 85
  • 124
  • What do you mean by real sh? There are lots of shells, including bash, that claim to implement posix sh with extensions, and running in all of them is about as good as you can get. But even if you do stick to posix sh are you using any other programs that aren't standard? – Mark Baker Oct 14 '08 at 14:22
  • 1
    "Real sh" means just that - the real Bourne Shell, such as /bin/sh on a FreeBSD machine. Ubuntu had all sorts of problems when they switched from using bash to dash as their /bin/sh, because scripters unknowingly included bashisms that failed on a more compliant implementation. – Kirk Strauser Oct 14 '08 at 14:42
  • The real Bourne Shell wasn't posix compliant, so shouldn't be installed as /bin/sh on any modern unix. – Mark Baker Oct 14 '08 at 15:28
7

Bash. It's standard.

Paul Nathan
  • 39,638
  • 28
  • 112
  • 212
6

The problem with csh is that it's crap for scripting, as explained here. There's no real reason why you shouldn't use it as an interactive shell, but most people find it confusing having to learn two different shells and not being able to try out bits of their scripts on the command line, so it's easiest to use the same for everything.

The obvious candidates for an interactive shell are bash, dash, zsh and {pd,}ksh. All of these implement the posix shell standard, with some minor extensions. Pick whichever you like for interactive use, I'd tend to go with bash just because it's the standard on linux but they all have their merits and zsh in particular seems popular.

If you're writing a script that you intend to be portable, use #!/bin/sh, and make sure you use standard posix shell syntax. If it works on both bash and ksh it's probably standard. There are some old versions of unix which have a non-standard /bin/sh but I wouldn't bother with that unless you know you have to. More of a problem for portability are all the command line tools you call from your script.

Mark Baker
  • 5,588
  • 2
  • 27
  • 25
  • 3
    The "csh considered harmful document" is worth reading, but I think people should also read "Top Ten Reasons not to use the C shell" at http://www.grymoire.com/Unix/CshTop10.txt, which makes a much better case about the problems of using csh or tcsh for scripting. I would also add one other defect of csh: no shell functions, so csh scripts are a spaghetti of little scripts all sourcing each other. So much for being modelled on C! In any case, except for little throwaway scripts, for which I use bash, I prefer scripting in Python. – Andrej Panjkov Jul 23 '09 at 02:51
4

Nobody mentioned the Debian based standard for sh, Its the Debian Almquist shell dash. Its is fully POSIX compliant and has a very fast startup, which is why Debian/Ubuntu use it for /bin/sh.

So I use bash for my interactive shell, but only dash for scripting. That way i know my scripts are at least POSIX compliant, and will run on any other POSIX shell. ... I know portability is more than the shell, but its where I draw the line.

J. M. Becker
  • 2,755
  • 30
  • 32
3

I'm not big Ruby user but http://rush.heroku.com/ looks interesting

Soft
  • 31
  • 3
3

It's probably best to stick with bash simply because it's the most widely used as a shell and any tutorials or help you may receive from someone will most likely use bash. However, I have started using zsh for all of my scripts and I have found it to be far superior to bash in terms of scripting.

user34292
  • 41
  • 1
2

Just don't use Korn Shell (ksh).

Unless you have perfect typing and never need to use the backspace key.

TM.
  • 108,298
  • 33
  • 122
  • 127
  • Why? I've never had any problems with using the backspace key in Korn shell. – Jonathan Leffler Oct 14 '08 at 02:16
  • It's true, sort of, but only if your system is set up wrongly. If your terminal generates a DEL (0x7f) for backspace but you have stty erase set to ^H, then ksh won't backspace properly. bash will anyway because it always recognises DEL as backspace whatever stty erase is set to. – Mark Baker Oct 16 '08 at 14:06
  • OK...that makes some sort of sense. I've never noticed the problem, but probably because I've seldom worked on a keyboard that generates DEL. – Jonathan Leffler Oct 18 '08 at 17:44
  • In true ksh, typing a backslash followed by a backspace embeds both the backslash and the backspace in the command line. I think pdksh did away with that particular insanity. – Joshua Feb 27 '09 at 21:35
1

I like ksh actually. It's a bit more consistent than bash because it does not try to support any csh constructs. tcsh, in my experience, is least compatible with other shells, and I avoid it. I try to write scripts to sh, but ksh does have some nice features like exporting and setting a variable on one line. I try to preserve compatibility with bash as well, since it is full-featured and common. To write portable shell scripts, which is more important than selecting the "best" shell, you might consult this book.

Portable Shell Programming: An Extensive Collection of Bourne Shell Examples (HP Professional Series) by Bruce Blinn (Paperback - Oct 29, 1995) amazon.com

Jason Catena
  • 567
  • 4
  • 7
1

I use pdksh all the time without having anything close to perfect typing (perhaps you need to fix your termcap?).

ksh is the standard, csh is a standard and bash is 'standard', but on linux only. Better to target ksh.

1

I came also from csh, tcsh to bash. It's different but after some time, at least as nice as the c-shells.

For Scripting I would recommand ksh, because it's available on most Unixes (Solaris, HP-UX , OSF/1 (The best UNIX ever ;) - for it's time)) and it has good features. With Korn you can programm most of the scripts. Sporadicaly you would like to get more then a number, as return value from a function, or you have some data that you can not put in a simple array, or you need something that has better capabilities in case of regegs, or what ever, then I would propose perl.

user224243
  • 399
  • 1
  • 5
1

For scripting, try using dash for a while to get a good feel for what is portable. If you ever use bash to write a shell script, please explicitly declare bash in the scripts shebang.

For your personal console use, experiment with what is out there. Find something that you're comfortable with. Be eccentric and annoy all your sysadmin friends by picking up a shell that has to be compiled from source for every machine you care to use it on.

  • LOL. I'm not trying to make enemies with sysadmin. In the small dev shop I work in, I am my own sysadmin. – Scottie T Apr 09 '10 at 19:47
1

I think FISH is the best, is has syntax highlighting(for commands that don't exists) and it can autofill. And it is very easy to learn.

1

For writing actual scripts, I prefer ksh, which has several extensions useful for programming and fixes one of my pet annoyances.

bash is my preference for interactive sessions, but that is more a matter of personal preference than anything else. Just be sure it is a Bourne-type shell.

Community
  • 1
  • 1
Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148
-4

Select one: a. tcsh b. ksh c. zsh d. login e. bash

I would use login. Just sayin.

  • 1
    Do you understand what a login shell is? It's not comparable to tcsh, ksh, zsh, bash, etc. because it's merely a shell that runs when your user ID logs in for an interactive session. – nixpower Jul 21 '15 at 16:17