Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash vs csh vs others - which is better for application maintenance? [duplicate]

Possible Duplicate:
What Linux shell should I use?

I am starting to get proficient in a Linux environment and i'm trying to pick a weapon of choice in terms of command shell scripting (as i'm still a big n00b at this) that will help me (and others) manage, test and administer a set of server side applications running on a *NIX environment.

My question is: What is(are) the preferred command shell(s) out there when the following criteria are considered:

  1. How easy is it to learn/understand for a junior dev who has never had an exposure to shell scripting?

  2. Is there a big pool of developers out there that know this shell script?

  3. Is it safe and easy to use - will script errors be silent or give intelligent error output, will it let the uninitiated shoot them selves in the foot?

  4. How portable is it? - Can i expect the same script to run in OpenSolaris as well as Redhat, FreeBSD? (granted command syntax and options for specific OS will change accordingly)

  5. How standard is it? Is it expected to be included on most distro's of *NIX or does it have to be installed additionally?

I understand that there are camps out there who hold strong feelings for/against specific command shells, i am just looking for an informed opinion.

like image 698
LoudNPossiblyWrong Avatar asked Nov 30 '10 18:11

LoudNPossiblyWrong


People also ask

Is CSH better than Bash?

Speed: BASH is faster and C shell. Features: BASH and C shell work both on Linux and Unix. CSH has its unique features, and BASH incorporated other shell features like CSH and KSH (Korn Shell) along with its own unique features. This made BASH widely used shell having more features than CSH.

Is shell faster than Bash?

Both shells are 2–30 times faster than bash depending on the test.

Which is the best shell for Linux?

Bash, or the Bourne-Again Shell, is by far the most widely used choice and it comes installed as the default shell in the most popular Linux distributions.


4 Answers

These days, just about any non-embedded (or large embedded) operating system has a POSIX:2001 a.k.a. Single Unix v3 compatibility layer. This is native on unix platforms (Linux, Mac OS X, Solaris, *BSD, etc.) and installable on other platforms such as Windows and Android. POSIX specifies a shell language, usually known as POSIX sh. This language is derived from the Bourne shell.

Most unix systems have one of two implementations of POSIX sh: ksh or bash, which have additional useful features compared to POSIX. However some less mainstream systems (especially embedded ones) may have only POSIX-mandated features.

Given your objectives, I see three choices:

  • Restrict yourself to POSIX sh. Pro: you don't have to worry about differing variants, since there's a standard and compliant implementations are readily available. Con: you don't benefit from bash and ksh's extensions.
  • Use the intersection of ksh and bash. This is attractive in appearance, but it does mean you have to use two reference documents instead of just one — and even the features that bash and ksh have in common don't always use the same syntax. Figuring out which one you want to use on a given system is also a pain.
  • Choose one of ksh or bash. Both bash and ksh are available on all unix-like platforms and on Windows. Both have an open source implementation (the only one for bash, ATT ksh93 for ksh) that can be installed on most platforms. I'd go for bash over ksh for two reasons. First, it's the default on Linux, so you'll find more people who're used to it. Second, there are systems that come with an older, less-featured implementation of ksh; even if you can install ksh93, it's another thing you have to think about when deploying.

Forget about csh for scripting, and forget about zsh if you want common default availability.

See also What are the fundamental differences between the mainstream *NIX shells?, particularly the “for scripting” part of my answer.

Note that shell programming involves other utilities beyond the shell. POSIX specifies those other utilities. “Bash plus other POSIX utilities” is a reasonable choice, distinct from “POSIX utilities (including sh)”.

like image 97
Gilles 'SO- stop being evil' Avatar answered Nov 05 '22 19:11

Gilles 'SO- stop being evil'


csh is almost always wrong.

like image 20
onemasse Avatar answered Nov 05 '22 20:11

onemasse


Z shell (zsh)

It's said zsh is the most powerful for now so I would recommend trying it.

  1. No matter which shell you learn - their syntax is very similar. Only built-in commands may slightly differ. But don't choose those old and unmaintained.
  2. Bash is the most popular. But almost every command in bash works in zsh the same way. There are some exceptions of course.
  3. AFAIK, every shell handles it the same way. But be warned - shells are stupid, they are not as smart as programming languages.
  4. I saw zsh working on all Linuxes, FreeBSD and OpenSolaris.
  5. See 4. Distros have zsh in their repos.

Why I prefer zsh (Z shell) to bash:

  • files matching like this: for file in ./**/*.java; do ... (I mean ./**/*.ext)
  • wants me to confirm when I do rm * :)
  • tab-autocompletion is a lot better, I can write dmdomi[tab] and it suggests dnddomainname. java wants class name as the first parameter, zsh will suggest all classes available in the package and all subpackages.

But you are not limited to zsh only. If something does not work for you, you just write it in bash or sh. This is what is "#!/bin/bash" on top of the script for. :-)

To start quickly, use my .zshrc config: http://www.rozne.geozone.pl/.zshrc The only thing you should change there is export LANG="pl_PL.UTF-8". You probably don't want Polish locale.

like image 42
Nowaker Avatar answered Nov 05 '22 20:11

Nowaker


Shell scripts for any *nix shell are generally deceptively simple. Easy things are usually easy, sometimes hard things are easy, sometimes easy-seeming things are hard. No shell is particularly better than the others in this area but some are worse (I can't seriously recommend csh). Some will say that bash is the worst 'modern' shell, which may be true but you can't completely escape it anyway.

There's an argument to be made that using the most 'popular' shell is best for maintainability for the same reason Windows is best (and I'm not saying that it is): It's easy to find people you can hire who know how to use it. There are simply more people who have at least a passing familiarity with bash-specific features, say, than ksh or zsh. Finding people who actually understand what they're doing is another matter.

All shells have various gotchas, corner-cases and weird behaviors. Mostly it comes down to what you're used to. Shooting yourself in the foot is what I'd call a grand Unix tradition and no *nix shell can truly keep you safe.

Nearly every shell you'll see is highly portable to almost every platform. Even though this is true you won't necessarily be able to run the same (say) bash script on three different boxes unless you were careful about what utilities you used and which options you passed them. Writing portable shell scripts is hard for reasons having nothing to do with which shell they're written for.

Nearly every Linux uses bash by default and has most shells available. FreeBSD includes sh, csh and tcsh by default with bash and others in ports. Once upon a long time ago, Mac OS X used tcsh by default, but it now uses bash by default, and includes zsh along with most common shells. Beyond that I cannot comment.

Personally I use bash out of (mostly) inertia. If I weren't so familiar with it already I would use zsh instead.

like image 43
sorpigal Avatar answered Nov 05 '22 19:11

sorpigal