From owner-freebsd-hackers Sat Nov 16 20: 1:18 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7E80137B401 for ; Sat, 16 Nov 2002 20:01:16 -0800 (PST) Received: from scaup.mail.pas.earthlink.net (scaup.mail.pas.earthlink.net [207.217.120.49]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1C3BA43E3B for ; Sat, 16 Nov 2002 20:01:16 -0800 (PST) (envelope-from tlambert2@mindspring.com) Received: from pool0237.cvx40-bradley.dialup.earthlink.net ([216.244.42.237] helo=mindspring.com) by scaup.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 18DGcN-00035x-00; Sat, 16 Nov 2002 20:01:07 -0800 Message-ID: <3DD71418.470EAB94@mindspring.com> Date: Sat, 16 Nov 2002 19:59:20 -0800 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Lyndon Nerenberg Cc: dhh@monroe.net, freebsd-hackers@freebsd.org Subject: Re: finding unmatched quotes in shell scripts References: <200211170159.gAH1xCG1052133@orthanc.ab.ca> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Lyndon Nerenberg wrote: > I've tried a number of syntax-colouring editors, to no avail. The quotes > (single, double, and back) *are* balanced, according to everything I've > thrown the script at. That's why I'm more interested in something that > can actually parse Bourne shell syntax (quiet Terry - I *know* what > you're going to say) and dump out what it thinks the parse tree looks > like. The problem isn't with the quotes being unbalanced, it's something > else that's making the shell ignore one (or more) of those quotes. Oh, you do? 1) CCsh, from Comeau Computing, is available for Linux, which means it should run under Linux emulation. It would tell you where the problem is, kicking it out as a compiler error. 2) Running the code under different shells that claim to implement the POSIX 2 syntax plus incompatabilities to lock you into using them^W^W^W^W^W^W^Wextensions, like "bash", is likely to get you different errors, which would enable you to find the problem (this is called "parallax debugging"; the technique has fallen into disuse because everyone assumes homogenous tools these days). 3) The sources for the "bash" shell include a file called "parse.y", which is an almost complete POSIX.2 shell syntax parser; it would be very easy to modify this to accumulate a parse tree, and print it out, if you were interested in whring your own tool. 4) The highlighting editor is a good idea. Specifically, if you highlight quote material with different highlighting based on the quoting, and include non-activations of double in single or single in double, or escaping via \", then the problem should be obvious: it will be any place the highlighting spans more than 1 line. 5) You could write a tiny yacc/lex grammar and/or a small "awk" sript to complain about open quote line spanning, probably in less than an hour. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message