All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jilles Tjoelker <jilles@stack.nl>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Chet Ramey <chet.ramey@case.edu>,
	Stefano Lattarini <stefano.lattarini@gmail.com>,
	dash@vger.kernel.org
Subject: Re: [BUG] dash doesn't report syntax error when it should on stray "fi"
Date: Wed, 25 Apr 2012 00:47:03 +0200	[thread overview]
Message-ID: <20120424224703.GA24960@stack.nl> (raw)
In-Reply-To: <20120423195458.GB13576@burratino>

On Mon, Apr 23, 2012 at 02:54:58PM -0500, Jonathan Nieder wrote:
> Chet Ramey wrote:

> > The way I read 2.10.2, Posix requires that the "fi" resolve to the
> > reserved word `fi' in this case, since it's in a position where a
> > command name is expected (Rule 1, [Command Name]).  I would think that
> > would make it a syntax error in any application, conforming or not.

> Yes, I think you're right.

> For some reason I thought that using reserved words in ways not
> permitted by the grammar produced undefined behavior, to support
> shells with extensions like the arithmetic "for".  But now that I read
> more closely, it looks like "function", "[[", "]]", and "select"
> produce unspecified behavior but everything else is pretty well
> specified.  Thanks for clarifying.

In what way does a lone "fi" differ from constructions like the below,
which do not match the POSIX grammar but are accepted by some subset of
shells that attempt to comply to POSIX:

case x in (esac) ;; esac

for i; do echo "$i"; done

for i;
do echo "$i"; done

for i { echo "$i"; }

for ((i = 0; i < 10; i += 1)) do echo "$i"; done

f() :

The only difference seems to be that the lone "fi" is somehow "wrong"
while the above are not "wrong". That's too vague for a specification.

Unfortunately, the XCU volume is very thin on constraints (as found, for
example, in the C standard). Many ways to do things "wrong" are instead
left open for implementation extensions. In practice, many such
extensions exist.

That said, rejecting the lone "fi" is still a quality of implementation
issue, particularly because dash's current behaviour is poorly defined.
I fixed it in FreeBSD a while ago (9.0 has the fix).

In making this change, a testsuite is very useful to guard against bugs
and to ensure no cases are missed, but latent bugs in shell scripts may
still cause annoyance. If there is an error in a command substitution
that is normally not executed, most shells (except ash derivatives) will
not notice this.

For example, FreeBSD 9.0's sh is one of the few shells that detects the
error in:

if false; then `fi`; fi

-- 
Jilles Tjoelker

  reply	other threads:[~2012-04-24 22:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-23 16:53 [BUG] dash doesn't report syntax error when it should on stray "fi" Stefano Lattarini
2012-04-23 17:03 ` Jonathan Nieder
2012-04-23 17:09   ` Stefano Lattarini
2012-04-23 19:27   ` Chet Ramey
2012-04-23 19:44     ` Jonathan Nieder
2012-04-23 19:48       ` Chet Ramey
2012-04-23 19:54         ` Jonathan Nieder
2012-04-24 22:47           ` Jilles Tjoelker [this message]
2012-04-23 19:53       ` Stefano Lattarini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120424224703.GA24960@stack.nl \
    --to=jilles@stack.nl \
    --cc=chet.ramey@case.edu \
    --cc=dash@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=stefano.lattarini@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.