Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 May 2000 14:12:52 -0400
From:      "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com>
To:        Duke Normandin <dnormandin@freewwweb.com>
Cc:        "'freebsd-questions@FreeBSD.org'" <freebsd-questions@FreeBSD.ORG>
Subject:   Re: csh script syntax error
Message-ID:  <20000511141252.A35223@cc942873-a.ewndsr1.nj.home.com>
In-Reply-To: <00ef01bfbb63$b3bb0d80$73dba7d1@dnormandinfreewwweb.com>; from dnormandin@freewwweb.com on Thu, May 11, 2000 at 08:29:18AM -0600
References:  <00ef01bfbb63$b3bb0d80$73dba7d1@dnormandinfreewwweb.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, May 11, 2000 at 08:29:18AM -0600, Duke Normandin wrote:
> On Wednesday, May 10, 2000 10:47 PM Crist J. Clark
> <cjc@cc942873-a.ewndsr1.nj.home.com> wrote:
> 
> 
> >On Wed, May 10, 2000 at 06:07:34PM -0600, Duke Normandin wrote:


> >DO NOT USE CSH FOR SCRIPTS. Use /bin/sh. (And I use tcsh for my
> >interactive shells, wouldn't dream of writing scripts in it.)
> 
> 
> I've been reading documents on the www about this issue -- something to
> the effect that the C Shell is "evil". I'm not in a position to judge, although
> the same could be said about C or Perl I suppose, *if* a person isn't inclined
> to RTFM, and is a sloppy programmer. Of course, there is also the fact that
> sh is "standard" across most *nix flavors (I think?) which fact should be
> enough for me to drop csh.

csh is pretty standard across UNIX flavors. sh is always there, but
there can be compatibility issues (is it Bourne or Korn for one
thing). The primary problem is that you cannot do some basic things
like,

  $ command 2> /dev/null

In csh. There is the hack,

  > ( command > /dev/tty ) >& /dev/null

But it is just that, a hack that does not always work as desired. The
csh syntax looks familiar to someone familiar with C... at first, but
its limitations quickly are apparent. csh makes you do things in
odd ways to get around the limited syntax. In sh I can just,

  if ls | grep -q '.txt'; then
      echo ".txt-files found"
  fi

Best way I can think of in csh is,

  ls | grep -q '.txt'
  if ( $? = 0 ) echo ".txt-files found"

Another huge thing is the inability to direct the output of a loop or
other groupings of commands in csh. In sh, I can,

  for FILE in *.txt; do
    command1 $FILE |
    command2
  done | command3

Where the file is an arg to command1 whose stdout is sent to
command2. Then the output of the whole loop is sent to command3. I
can't think of a way to do that in csh with one script or without a
temporary file.
-- 
Crist J. Clark                           cjclark@home.com


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?20000511141252.A35223>