From owner-freebsd-questions@FreeBSD.ORG Tue Dec 30 18:26:00 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A2D9916A4CE for ; Tue, 30 Dec 2003 18:26:00 -0800 (PST) Received: from zim.0x7e.net (zim.0x7e.net [203.38.184.132]) by mx1.FreeBSD.org (Postfix) with ESMTP id D65E943D55 for ; Tue, 30 Dec 2003 18:25:28 -0800 (PST) (envelope-from listone@deathbeforedecaf.net) Received: from goo.0x7e.net ([203.38.184.164] helo=goo) by zim.0x7e.net with smtp (Exim 3.36 #1) id 1AbW30-000HSC-00; Wed, 31 Dec 2003 12:55:22 +1030 Message-ID: <00d601c3cf45$57d07c40$a4b826cb@goo> From: "Rob" To: "Daniela" , References: <200312290334.25341.dgw@liwest.at><009801c3cdc9$88507280$a4b826cb@goo> <200312310133.53578.dgw@liwest.at> Date: Wed, 31 Dec 2003 12:55:22 +1030 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Subject: Re: Complex quoting task in tcsh X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Dec 2003 02:26:00 -0000 On Wednesday 31 December 2003, Daniela wrote: > On Monday 29 December 2003 05:06, Rob wrote: > > Daniela, > > > > This isn't the answer you would like, but tcsh is generally considered a > > bad language for writing scripts*. It's an excellent command-line shell, > > but scripts are not its strong point. > > > > One reason is the one you've just run into - quoting is a little flakey, > > especially when you try to do something tricky. > > > > For 'basic' scripts, either sh(1) or ksh(1) is usually the way to go. As > > an example, here's your line-checking question, using sh and FreeBSD > > commands: > > > > cat somefile | while read LINE ; do > > if echo "$LINE" | grep -q '^#' ; then > > # do something with $LINE > > fi > > done > > Thanks a lot, that grep -q thing also works for tcsh. > Excellent! > > > For more complex work, perl or python are usually recommended. > > You can do lots of stuff with shellscript: look at user.berklix.org/~dgw > Absolutely - the whole /etc/rc structure for example. I guess what I meant by 'complex' was string matching & manipulation. If I'm writing a shell script that uses awk and sed to chop things up, it starts to get clumsy and hard to read. At that point I'll usually turn it into a perl script. > > > On the other hand, if you just want to filter the comments out of a > > file, put > > > > grep -v '^#' > > > > at the start of your pipeline. > > > > * Csh Programming Considered Harmful (1996) > > http://www.perl.com/pub/a/language/versus/csh.html > > Csh is not harmful at all -- it allows for great optimizing for certain tasks. >