NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/57997: sh(1) allows an empty list in if statements
The following reply was made to PR bin/57997; it has been noted by GNATS.
From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: bin/57997: sh(1) allows an empty list in if statements
Date: Tue, 05 Mar 2024 06:19:50 +0700
Date: Mon, 4 Mar 2024 22:15:02 +0000 (UTC)
From: RVP <rvp%SDF.ORG@localhost>
Message-ID: <20240304221502.A9EC91A923B%mollari.NetBSD.org@localhost>
| OK, then this PR can be closed.
Will do.
| (And the man-page could note that an
| empty `list' is fine after `then' for NetBSD's /bin/sh.)
I don't think that should happen either - this is just ancient
behaviour that's being retained, not something to be advertised
as a feature that anyone really ought to be using.
I think (but don't quote me) that the only place the sh man page
notes that this is possible, is in function declarations, where
we allow
func() {
}
with no commands in the func body (also not POSIX syntax). That
one is deliberate, rather than just retained old code.
kre
ps: it isn't just "then": 'if true; then elif then else fi'
'works' just fine as one like like that, or with interspersed
newlines. (I'm not sure why a non-empty command is needed after
'if' but not after 'elif' ... more historic baggage).
I suspect some of the reason for this is that the ! command
(or operator, or whatever that thing really is) did not
originally exist, to execute some commands when something failed,
rather than succeeded (and not using || which isn't always
appropriate) required (in standard sh syntax)
if whatever_test; then : ; else commands_to_run; fi
and that ':' confused people who weren't sure what it meant.
I'm guessing (with no real basis for it) that avoiding the
need for that might be part of (or even wholly) the reason that
empty commands were allowed (and the other places just get it
from symmetry).
Also note that an actual executable command is not needed (in
POSIX syntax) just something which might be, so
E=
if whatever_test; then $E ; else commands_to_run; fi
is perfectly valid POSIX syntax, even though $E is nothing.
Home |
Main Index |
Thread Index |
Old Index