No Next Item No Next Conference Can't Favor Can't Forget Item List Conference Home Entrance    Help
View Responses


Grex Systems Item 40: The Unix shell item
Entered by cross on Sun Sep 17 00:22:23 UTC 2006:

Debate and study the differences between Unix shells in this item.

35 responses total.



#1 of 35 by remmers on Mon Sep 18 15:16:46 2006:

Bourne shell and its derivatives = good
C shell and its derivatives = evil


#2 of 35 by gull on Mon Sep 18 18:57:08 2006:

C shell is okay as long as you don't try to write scripts in it.


#3 of 35 by other on Mon Sep 18 20:14:11 2006:

Would someone knowledgeable in the subject please post a quick (and
preferably untainted by overt bias) summary of the primary feature
differences between the top several command shells?  If possible, also
list generally recognized positive and negative features of each.


#4 of 35 by cross on Tue Sep 19 04:01:35 2006:

The Bourne Shell: /bin/sh (or direct replacement)

The standard 7th Edition shell.  Originally, quite a weird implementation
(it allocated memory by trapping signals and increasing the size of the data
segment instead of just calling malloc, and used preprocessor symbols to
make the code look like a sort of weird variant of ALGOL).  Most modern
versions contrain job control.

The C-Shell: /bin/csh

Developed at Berkeley by Bill Joy.  Descended from the 6th Edition shell
and, while it has some useful features (job control, command history and
associated syntax for its manipulation, file name completion, the use of the
tilde (~) to refer to a user's home directory [default current user]), it
lacks some of the better ones incorporated into the Bourne shell (like the
ability to redirect individual file descriptors.  E.g., for output, you can
either redirect stdout (>) or stdout and stderr together (>&).  In
particular, you cannot easily redirect stderr independently of stdout).  CSH
was designed to have a "C-like" syntax, but I've never really understood
this; it doesn't look particularly C-like to me.  At this stage, mostly
historical.

The Tenex C-Shell: tcsh (non-standard)

This took the C shell, and added to it "Tenex-style" command and filename
completion, and command line editting using vi or emacs style keybindings
(similar to GNU's readline library).  Much more usable than pure C shell
once you get the hang of it.

The Korn Shell: /bin/ksh

Developed at AT&T by David Korn and others.  Derived from the Bourne shell,
but with command recall facilities similar to CSH and many other advanced
features (a command-line editting facility with either emacs or vi modes,
etc).  Supposedly the basis for the POSIX shell, though most systems ship
some sort of Bourne-like shell or derivitive, or the C shell.

The Bourne-again Shell: bash (non-standard)

The GNU reimplementation of the Bourne shell, with lots of new features and
enhacements.  It features command and filename completion, command line
editing, job control, command history and recall with editting, etc.  Pretty
much standard on Linux, much more capable than the original Bourne shell,
and containing pretty much the union of features of all the shells
previously mentioned.  Often criticized for being *too* big and
correspondingly slow.

The 9th Edition Shell: rc (non-standard)

A brand new shell with a syntax reminiscent of the Bourne shell, but far
more regular.  This one actually looks kinda like C; it's far simpler than
any of the others listed here,  but remains powerfl.  It has been adopted as
the standard shell under Plan 9.  Cedes things like job control, history,
command history and command line editing to other programs (under Plan 9,
the window system mostly).

The Extensible shell: es (non-standard)

Based on a Unix-only clone of rc, featuring an embedded Scheme interpreter.
Interesting, but not hugely popular.  A patch to add job control exists.

The Z shell: zsh (non-standard)

Another Bourne-derived shell, quite full-featured.  Nate and Jeff are both
users of zsh; perhaps they can comment further.

I think that's most of the biggies.


#5 of 35 by twenex on Tue Sep 19 15:14:16 2006:

Some of the BSDs (and probably some of the Linux distributions) also used
cut-down or statically-linked shells such as ash, either for system repair
or as the default shell for root (the administrator account). 

ZSH has some nifty features, such as being able to go to a directory by typing
its name alone, instead of after "cd", and completion for just about
everything (such as command options and manpages). For example, if I have the
following files in my home directory:

README_Solaris8.txt
README_Solaris9.txt
REALLY_LONG_FILE.txt

and want to read README_SOlaris9.txt. If I type:

cat R<tab><tab>

The shell will beep on the first <tab> and display a list of files beginning
with R. If I then type the letters the two README files have in common,
("EAD") and then <tab> the shell will type out:

$ cat README_Solaris

If I then type 9<tab>, the shell will then complete README_Solaris9.txt.

It's even more useful when trying to find a manpage!


#6 of 35 by gull on Tue Sep 19 21:14:12 2006:

One feature I remember seeing somewhere, but now can't remember where, 
is a directory stack.  You could 'push' on the current directory, 
change to another one, do some work, then 'pop' back to the original 
one.  It's a feature I've occasionally wished for when I was deep in a 
directory hierarchy.


#7 of 35 by cross on Wed Sep 20 04:11:16 2006:

tcsh has that feature; I suspect bash and a few of the others do as well. 
Wow, I've forgotten a lot.  I do remember that csh does the same.


#8 of 35 by naftee on Wed Sep 20 04:38:30 2006:

there's also tclsh .


#9 of 35 by cross on Wed Sep 20 05:11:41 2006:

Probably not what you'd want to use for interactive use....


#10 of 35 by remmers on Wed Sep 20 13:10:23 2006:

Re #6:  pushd and popd are in csh, tcsh, and zsh (but not sh or ksh).


#11 of 35 by cross on Wed Sep 20 22:15:38 2006:

John, did you check bash at all?


#12 of 35 by gull on Wed Sep 20 23:24:22 2006:

Looks like bash has it, too.  What's weird is I thought I'd looked for 
it and failed to find it.  I think I was probably looking at the 
bash(1) manpage instead of the bashbuiltins(1) one.


#13 of 35 by cross on Wed Sep 20 23:35:28 2006:

That's another complaint about bash: too many man pages and startup files.
Well, that's my complaint, anyway.


#14 of 35 by nharmon on Thu Sep 21 00:30:10 2006:

zsh, simple yet powerful. I've been using it ever since my slackware days.


#15 of 35 by gull on Thu Sep 21 16:44:03 2006:

Re resp:13: I'd agree with that criticism.  I suppose the classic 
GNUish answer would be to use the info pages, instead, but I've never 
liked info.


#16 of 35 by twenex on Thu Sep 21 16:44:44 2006:

No, neither have I.


#17 of 35 by remmers on Thu Sep 21 17:48:01 2006:

Re #11: Oops, yes, checked bash but forgot to list it.


#18 of 35 by cross on Thu Sep 21 19:35:09 2006:

Party of the problem with info pages is that they force a specific usage
model.  It works fine if you "live" within emacs and are used to that style,
but kind of sucks if you want to, say, pipe info through other things, etc.


#19 of 35 by naftee on Fri Sep 22 03:15:00 2006:

re 9 srsly


#20 of 35 by arthurp on Thu Mar 22 09:06:02 2007:

I have been using bash for several years.  Before that I was a tcsh user
for several years because it was better than csh (a few years) by a lot,
and those two supported command aliasing while bash did not at that
time.  Once Bash got command aliasing (and I actually noticed it) I got
tired of making sure my environment had tcsh.


#21 of 35 by yecril71pl on Sun Oct 7 12:50:46 2007:

How do I detect that the previous command has been suspended?
csh has $status set to 1 on such occasions.  This is the same as when the
command returned EXIT_FAILURE.


#22 of 35 by remmers on Sun Oct 7 14:34:59 2007:

Sh and bash use $? for exit status.


#23 of 35 by yecril71pl on Mon Oct 8 10:48:34 2007:

So they do; it does not affect my question: how do I detect that the previous
command has been suspended?  I would expect some high bit set in the return
code in order to distinguish it from a regular exit.


#24 of 35 by remmers on Mon Oct 8 13:07:55 2007:

I don't know the answer, and a little Google searching (which I imagine
you've tried too) didn't turn one up for me.  But since a suspended
command hasn't really "exited", I'm not sure I'd expect suspension to be
reflected in the value of an "exit status" variable anyway.

Does someone else know?

On a somewhat related matter, my searching did turn up a difference
between bash and tcsh in the semantics of the "&&" operator.  If you do

    echo one && sleep 20 && echo two

in bash, and then suspend the sleep with ctrl-z, "$?" is set to 0 and
"echo two" is executed immediately, even though the sleep hasn't exited.
 But if you execute the same sequence in tcsh and suspend with ctrl-z,
"$?" is set to 1 and "echo two" is *not* executed.

Hmmm...  I wonder what the correct POSIX behavior is.


#25 of 35 by yecril71pl on Mon Oct 8 16:44:54 2007:

Neither do I --- but it would be obvious for POSIX to follow Bourne.


#26 of 35 by papa on Tue Feb 14 00:14:40 2017:

After tiring of the Grex menush, I decided to give tcsh a try for historic
interest (bash is my standard shell on Un*x systems where I have a choice).

I installed the tcshrc Project (https://sourceforge.net/projects/tcshrc/)
initialization files to give myself a head start. I found that the Project
assumes you're using a variety of Linux, so it took a little hacking to get
some of the features working on Grex's OpenBSD, which was both annoying and
fun.

I will not bother with tsch scripts beyond dabbling with the initialization
files. Within that range, although the syntax is different from the more
familiar Bourne-like shells, I have encountered no problems.

Overall, I like tcsh fine, with very little difference from bash for ordinary
use. I have not been able to get the incoming mail watch feature to work,
though I don't get much mail on Grex. tsch has a login watcher that I think
bash lacks which is interesting.

I guess that either tcsh or csh is or was the default shell on Grex because
the system-wide cshrc file looks like it's had quite a bit of customization.


#27 of 35 by kentn on Wed Feb 15 01:52:33 2017:

tcsh is my preferred shell and has been for a long time.  


#28 of 35 by papa on Wed Feb 15 03:54:16 2017:

Why do you prefer tcsh over something like bash? They seem
very similar to me.


#29 of 35 by kentn on Thu Feb 16 02:52:11 2017:

While they are similar, I like the vi command line in tcsh
much better than than in bash. I like all the features in
tcsh better. I don't do shell scripts in tcsh though.


#30 of 35 by papa on Thu Feb 16 03:38:20 2017:

I prefer Emacs key bindings for command line editingand
haven't noticed any problems with tcsh there.

I occasionally miss bash command syntax and redirection
options for longer complex commands. But it doesn't come
up often on Grex.


#31 of 35 by tod on Tue Mar 14 17:28:03 2017:

Long live bash and vi (though cash shell would make me happier)


#32 of 35 by papa on Thu May 18 23:17:56 2017:

I've been using tcsh (with the tcshrc package
https://sourceforge.net/projects/tcshrc/) since I came to Grex. It's not
bad, but the small differences with bash are becoming more annoying. I'm
thinking of switching back to bash.

tcsh can't find executables in the directory at the end of my $path list. Have
I missed some setting that will fix that?


#33 of 35 by papa on Thu May 18 23:24:59 2017:

I can't recreate the $path problem now. Never mind.


#34 of 35 by cross on Fri May 19 00:21:43 2017:

I used tcsh for nearly 20 years but switched away about a decade ago. Everyone
around me used bash, so I felt I should adapt instead of expecting the world
to accommodate me. Then I started using zsh most places.


#35 of 35 by cross on Fri May 19 00:22:14 2017:

Oh, PS: If you added or moved a command and experience that problem again,
try running `rehash`.

Response not possible - You must register and login before posting.

No Next Item No Next Conference Can't Favor Can't Forget Item List Conference Home Entrance    Help

- Backtalk version 1.3.30 - Copyright 1996-2006, Jan Wolter and Steve Weiss