Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Jan 2002 01:49:24 -0800
From:      "Crist J. Clark" <cjc@FreeBSD.ORG>
To:        "Brian T.Schellenberger" <bts@babbleon.org>
Cc:        Cliff Sarginson <cliff@raggedclown.net>, freebsd-questions@FreeBSD.ORG
Subject:   Re: shells confusion
Message-ID:  <20020126014924.I14394@blossom.cjclark.org>
In-Reply-To: <20020126070114.C8FD93FE5@i8k.babbleon.org>; from bts@babbleon.org on Sat, Jan 26, 2002 at 02:01:14AM -0500
References:  <20020126020430.P175-100000@BLAST> <20020126035658.GC1290@raggedclown.net> <20020126070114.C8FD93FE5@i8k.babbleon.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Jan 26, 2002 at 02:01:14AM -0500, Brian T.Schellenberger wrote:
> On Friday 25 January 2002 10:56 pm, Cliff Sarginson wrote:
> > On Sat, Jan 26, 2002 at 02:18:16AM +0200, Bernie wrote:
> > > hi,
> > >
> > > i'm planning to learn shell programming but i'm not sure
> > > on which one to choose...
> > >
> > > i've been reading in the 'FreeBSD unleashed' that people
> > > wanting to do shell programming should stay away from
> > > c-shell as it's realy good for interactive, but very bad
> > > for scripts. is this true?
> >
> > Yes and Yes.
> 
> I would not agree with this at all.  I find csh much more readable/sensible 
> than /bin/sh for interactive use.  Spaces don't matter; if statements are 
> vastly more readable, etc.
> 
> Now for really complex "shell" programming I use perl, but C shell is, IMHO, 
> a lot easier to write and read than /bin/sh.

Ack!

> There *is* one severe problem with csh that I know of: the quoting rules are 
> just plain broken; if you get into nested quotes things get screwy quickly.  
> I work around this with
> 
> set Q = "'"
> set QQ = '"'
> set $S = '$'
> 
> at the top of my scripts, but I freely admit that it is completely stupid 
> that I should have to do so, but writing
> 
> if ($a > 4) then
>      echo "$a is greater than 4"
> endif
> 
> vs.
> 
> if [[eval $a > 4]];;
>     echo "$a just tell me that's more readable.  I dare you."
> fi
> 
> (or whatever--the syntax is inexact) it just seems to be to be no contest: 
> csh wins, hands-down.

Uh,

  if [ $a -gt 4 ]; then
	echo "$a is greater than 4. This is quite readable."
  fi

> Plus the convenience of
> 
> if ($a =~ foo*)
> 
> vs. (as far as I can tell) having to do a switch just for string tests -- 
> again, csh is the scripting shell for me.

  if expr "$a" : 'foo.*' >/dev/null; then

The thing is that sh(1) can do a ton of stuff csh(1) simply
cannot. Try to do this,

  command 2>err.file

In csh(1). Or try,

  command1 |
  while read WORD REST; do
    ...
  done |
  command2

In csh(1).

[snip]
> > /bin/sh is the Unix common denominator of shells, so scripts
> > get written in it. They are not written in csh, because as
> > stated csh script is unusable for all practical purposes.
> 
> unusable???????  What on earch are you talking about?
> 
> I have many dozens of quite usable csh scripts.  And they are readable, too.

There are just so many things you simply cannot do in any sane way
with csh(1) like the few I eluded to above.
-- 
Crist J. Clark                     |     cjclark@alum.mit.edu
                                   |     cjclark@jhu.edu
http://people.freebsd.org/~cjc/    |     cjc@freebsd.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020126014924.I14394>