From owner-freebsd-questions Thu May 11 12:14:28 2000 Delivered-To: freebsd-questions@freebsd.org Received: from cc942873-a.ewndsr1.nj.home.com (cc942873-a.ewndsr1.nj.home.com [24.2.89.207]) by hub.freebsd.org (Postfix) with ESMTP id 65AF037BC3C for ; Thu, 11 May 2000 12:14:21 -0700 (PDT) (envelope-from cjc@cc942873-a.ewndsr1.nj.home.com) Received: (from cjc@localhost) by cc942873-a.ewndsr1.nj.home.com (8.9.3/8.9.3) id OAA35439; Thu, 11 May 2000 14:12:52 -0400 (EDT) (envelope-from cjc) Date: Thu, 11 May 2000 14:12:52 -0400 From: "Crist J. Clark" To: Duke Normandin Cc: "'freebsd-questions@FreeBSD.org'" Subject: Re: csh script syntax error Message-ID: <20000511141252.A35223@cc942873-a.ewndsr1.nj.home.com> Reply-To: cjclark@home.com References: <00ef01bfbb63$b3bb0d80$73dba7d1@dnormandinfreewwweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <00ef01bfbb63$b3bb0d80$73dba7d1@dnormandinfreewwweb.com>; from dnormandin@freewwweb.com on Thu, May 11, 2000 at 08:29:18AM -0600 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, May 11, 2000 at 08:29:18AM -0600, Duke Normandin wrote: > On Wednesday, May 10, 2000 10:47 PM Crist J. Clark > 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