Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Nov 2002 19:59:20 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Lyndon Nerenberg <lyndon@orthanc.ab.ca>
Cc:        dhh@monroe.net, freebsd-hackers@freebsd.org
Subject:   Re: finding unmatched quotes in shell scripts
Message-ID:  <3DD71418.470EAB94@mindspring.com>
References:  <200211170159.gAH1xCG1052133@orthanc.ab.ca>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3DD71418.470EAB94>