which unix shell is best?
December 25, 2007 12:28 PM   Subscribe

I have been using tcsh for a number of years now ( at least 12), and it seems that most OSes and most users have moved on to something better. Is there a reason for me to change, and if so, what is the best shell out there? ( main os is OSX 10.5, but use all sorts of linux/unix OSs ).

To be honest, while there are a few things that tcsh is clunky at, I am relatively happy with it. I am moving alot of my shell scripts over to python, so tcsh might not be so bad, but I would like to keep myself learning new things.

any advice?
posted by brent_h to Computers & Internet (25 answers total) 3 users marked this as a favorite
 
Pretty much everyone I know in the past ten years has learned bash, and these days bash is the default for most distro installs. Why? I'm not sure. I know that I'm more comfortable in bash because coming from a web scripting world the scripting syntax makes more sense to me ... but I haven't done enough tcsh to know the difference.

My suspicion is that since /etc/rc and cronrc files and other base system shell scripts *MUST* be written in bash, tcsh and csh have fallen into disuse as switching syntaxes all the time can cause some serious problems in absent-minded sysadmins' heads... not to mention their systems.
posted by SpecialK at 12:43 PM on December 25, 2007


Ah, here's an answer from comp.unix*: csh programming considered harmful, vintage 1996.
posted by SpecialK at 12:44 PM on December 25, 2007


tcsh used to offer a lot of features that the standard shell didn't, but at this point I think bash will do everything tcsh will, plus lots more besides.

I don't think there's all that much action in shell scripting anymore. You can obviously make perfectly functional programs that way, but most folks these days go for Perl or Python, because of the improved readability and much greater ease of use.

You might learn the bash basics, but I probably wouldn't put a ton of time into it.
posted by Malor at 1:16 PM on December 25, 2007


I like zsh, which is basically bash nowadays.
posted by todbot at 1:18 PM on December 25, 2007


Perl and Python also has the advantage of running on non-unix platforms without much trouble.

I prefer PowerShell.
posted by jeffamaphone at 1:19 PM on December 25, 2007


I don't know anyone who prefers a shell that isn't bash. Okay, one guy that uses zsh. Two now with todbot.

I can't imagine it ever being a big deal what shell you use, ever, but if you get familiarity with bash then you can deal with practically every newly-set-up system, since that's been the default nearly everywhere for the past long while now.
posted by blacklite at 1:29 PM on December 25, 2007


Wilfredo Sanchez used to lead the OS X engineering team and preferred tcsh. That's why OS X used to use tcsh as the default shell. So, you're not alone.
posted by kcm at 2:11 PM on December 25, 2007


(I should also mention that he worked on tcsh before he worked on OS X..)
posted by kcm at 2:12 PM on December 25, 2007


Use whatever shell you're most comfortable with. That's why different ones exist.
posted by mrbill at 2:15 PM on December 25, 2007


I use bash on servers I don't use that often and zsh on everything else.

If you use bash, you should read Power Shell Usage: Bash Tips & Tricks. It includes a few setting and tricks that really make using the shell better. Most of the tricks (especially up/down history completion) I have made work in zsh.

zsh has two things over bash: completion and globbing. It also has nicer prompts, global aliases, and a few other things, but those aren't that important.

Yes, bash has completion and the bash completion project certainly helps, but zsh is better. I can use tab completion for perldoc (2136 possibilities) and have it complete in 3 seconds and then instantly every subsequent time, thanks to caching. With bash, it's 5 seconds every tab.

zsh has recursive globbing. So, instead of using find(1) all the time, you can just do ls **/*. It also supports complex modifiers. For example, what's in my Sites directory that is a regular file that's also executable? ls Sites/**/*(.f+x) Also, since it's native to the shell, you don't have to know how -exec works or deal with piping, --print0, and xargs.

This said, it's a lot to learn and takes a bit to set up. I don't use zsh everywhere, since servers I use less often just aren't worth setting up and usually have an old zsh version.
posted by easyasy3k at 2:29 PM on December 25, 2007


I'd have to say that while bash and tcsh made it to the finish line (with bash way ahead), shell scripting is basically over.

If you want to learn something new, perhaps one of the high level languages? I resisted Java for years but it was entertaining enough when I finally got to it.
posted by tkolar at 2:36 PM on December 25, 2007


My shell of choice is fish.
posted by CautionToTheWind at 2:59 PM on December 25, 2007


I still like tcsh best. You're not alone.
Here's a slashdot thread to help you switch from tcsh to bash. But you shouldn't. I'm good friends with a former lover of tcsh's author, and I will represent tcsh until death do us part.
posted by jewzilla at 3:15 PM on December 25, 2007


I still use tcsh, even now that I'm off the BSDs and onto Debian (laptop, sigh). I like the syntax, I like the way it behaves, and, more importantly, I already have my .cshrc just the way I want it, and I'll be damned if I'm going to spend the hour or two it'd take to port it over to bash. I'll also never give up vi!

I used zsh for a while, and it wasn't bad, but I didn't get particularly attached to any of it's features.

And I'll echo everything everyone has said about shell scripting... aside from a little bit of sh scripting, and my .*rc files, I've never touched it - if it's a one-liner, tcsh + awk/sed/xargs will do fine. If it's more than that, perl is your friend.
posted by devilsbrigade at 3:32 PM on December 25, 2007


nth zsh. Most fantastic shell i've ever used when you get used to its power tricks and can do just about everything.
posted by arimathea at 4:06 PM on December 25, 2007


I'm an experienced Python programmer but I still prefer to use shell scripting for many things. I guess I mainly use it to drive lots of other programs so that I don't have to hardcode lots of details into Python scripts. It makes it much easier to reuse them.

My recommendation would be to use bash. A nice thing about it is that it is on almost every recently installed Unix or Unix-like system you will find. If you ever have to use someone else's computer you'll find you'll have to learn some bash anyway.
posted by grouse at 4:16 PM on December 25, 2007


nthing zsh, it's very similar to bash, so you don't lose much for those computers that don't have zsh available, plus some nice additional features (mostly prompting and autocompletion/globbing as mentioned above)
posted by freshgroundpepper at 5:18 PM on December 25, 2007


jeffamaphone-I prefer PowerShell.

The OP said he's using Mac OS X and various Linux/Unixes. PowerShell is totally irrelevant for his needs, since it does not run on anything but Windows.

SpecialK-My suspicion is that since /etc/rc and cronrc files and other base system shell scripts *MUST* be written in bash, tcsh and csh have fallen into disuse as switching syntaxes all the time can cause some serious problems in absent-minded sysadmins' heads... not to mention their systems.

Actually, base system shell scripts are usually executed with whatever the system's default is for /bin/sh. That is usually bash these days, but for instance, Ubuntu uses dash, not bash. Best practice is to avoid "bashisms", and write your base system shell scripts as POSIX shell scripts that will work no matter what the system's default shell.
posted by evariste at 5:37 PM on December 25, 2007


I was hard core tcsh user, as it was the first I learnt. But if you do scripts, you tend to always use "sh" to be compatible. (yes, sh, not bash! Stop assuming it's bash linuxers! I'm looking at you!) So I ended up "having to know" both bash style and tcsh style, ways of doing things. (foreach vs for and all that). So just using bash made it easier, and made me be better at making the scripts.

Once I made the prompts look the same, it was no difference.

Then I discovered a couple of bonus features, I really love ^R now (like emacs, search backwards in history), and I found UTF-8 (Japanese) to work more easily in bash.

But really either shell is fine to use, it was just easier to use/memorise just one subset.
posted by lundman at 5:43 PM on December 25, 2007


I'm quite happy with tcsh aside from a few niggles I'm sure you're familiar with. It's a highly underrated interactive shell, even if it's crap for scripting (but then, so are all the other shell scripting languages, urgh). Programmable completion, plenty of configuration options, decent usability.. I don't really think I'd gain much switching to zsh (except I'd have to install it myself in a lot of places) or bash (except I'd have to port all my existing settings). The crap stderr handling I encounter rarely enough that I can just drop into sh if I really need to get around it.

Really, I've used bash and zsh. The things I liked about them I found I could usually do just as well in tcsh, and it comes in the base system for most of my systems, so why not use it? I like learning new things too, but new shells don't seem to be a particularly good use of my time.
posted by Freaky at 6:23 PM on December 25, 2007


I use zsh for interactive/command-line, and made the transition from tcsh to bash to zsh years ago. Completion, globbing, etc. There are plenty of sample dotfiles for zsh, too. But I don't script with the shell: the most I'll do are loops through lists of files.
posted by holgate at 6:39 PM on December 25, 2007


I used to know that scripting-wise, it was best to write for a standard shell that you could be confident would be present on almost any system your script ended up on, which generally meant a sort of POSIX compliant shell, usually bin/sh.

For personal interactive-command stuff, you picked whatever you felt comfortable with. As a sysadmin, I tried to stick with whatever the default was, so I'd notice problems before the users did.

I don't know what the kids are using these days. Probably some combination of Ruby and a Wii controller.
posted by tew at 9:11 PM on December 25, 2007


Bash seems to be winning the popularity contest these days, but it's been a long time since I've used a machine that didn't have both a bash-like and C shell. So I don't think there's any reason for you to change if you don't want to.

Personally, I prefer ksh, but I don't have a ton of real arguments for its superiority over bash; I just have always used it and don't have any compelling reasons to change.
posted by Kadin2048 at 10:16 PM on December 25, 2007


bash. bash. bash. (bonk on the head), bash. 20 years ago t?csh was cool, a nice improvement over the standard /bin/sh. Every cool person used it. Not anymore, bash, bash, bash... I fight the urge to smack t?csh users upside the head with a dead fish almost every day.

No serious geek would use anything else. Use t?csh/zsh/ksh for personal use if it pleases you, but the world runs on bash/sh... (and Perl 5.6.1 or 5.8.3 depending on OS). t?csh is for greybeard sandal wearing old-timer people... bash, bash, bash...
posted by zengargoyle at 10:52 PM on December 25, 2007


#!/bin/bash
posted by flabdablet at 12:34 AM on December 26, 2007


« Older Handheld Hell   |   Shure SE310 vs. Etymotic ER6 with a catch. Newer »
This thread is closed to new comments.