Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: L A Walsh Newsgroups: gnu.bash.bug Subject: Re: error message for missing fi is not helpful Date: Wed, 12 Sep 2018 19:29:01 -0700 Lines: 91 Approved: bug-bash@gnu.org Message-ID: References: <12006574-8df4-d613-0603-51b77b703a3d@dwd.de> <3461cc07-6477-234b-83ea-30a6bc0c8d8c@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020000030903040400060307" X-Trace: usenet.stanford.edu 1536805765 1886 208.118.235.17 (13 Sep 2018 02:29:25 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Manuel Reiter , bug-bash@gnu.org To: chet.ramey@case.edu Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: <3461cc07-6477-234b-83ea-30a6bc0c8d8c@case.edu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14576 This is a multi-part message in MIME format. --------------020000030903040400060307 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 9/12/2018 6:35 AM, Chet Ramey wrote: > On 9/12/18 5:17 AM, Manuel Reiter wrote: > > >> Bash Version: 4.4 >> Patch Level: 12 >> Release Status: release >> >> ++ Description: >> >> When an if statement is not terminated by a fi, bash's error message is >> not helpful in locating the problem. >> > > This is tough to do in a bison-generated parser. If someone would like to > build the structures required to keep track of which conditional command > the shell is currently parsing, and incorporate that into an error > message, I'd be happy to look at it. > > Chet > This isn't *exactly* what you wanted, but this gives the line number of the last unmatched statement (but doesn't tell you what the statement was). The diff was against bash-4.4.23 (4.4 base w/23 patches) I can't speak for formatting or base-specific function usage, but I don't think there was any of those. Anyway, if you store the word in a separate array where the line # is stored, you _could_ list the matching word, but I suspect just the line it started on would be enough for most users. --- (eoftest.sh) #!/bin/bash if ((1)); then for i in 1 2 3; do echo wow --- > ./bash eoftest.sh eoftest.sh: line 10: syntax error: unexpected end of file from line 4. The wording was just what I threw in. I don't _need_ attribution for this if that makes it easier. --------------020000030903040400060307 Content-Type: text/x-diff; name="parse.y.diff" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="parse.y.diff" LS0tIHBhcnNlLnkub3JpZwkyMDE2LTA5LTExIDA4OjMxOjQ2LjAwMDAwMDAwMCAtMDcwMAor KysgcGFyc2UueQkyMDE4LTA5LTEyIDE5OjE0OjQ1LjU0MjgwOTczMSAtMDcwMApAQCAtNjAy MCw5ICs2MDIwLDIxIEBACiAgICAgICAgIHByaW50X29mZmVuZGluZ19saW5lICgpOwogICAg IH0KICAgZWxzZQotICAgIHsKLSAgICAgIG1zZyA9IEVPRl9SZWFjaGVkID8gXygic3ludGF4 IGVycm9yOiB1bmV4cGVjdGVkIGVuZCBvZiBmaWxlIikgOiBfKCJzeW50YXggZXJyb3IiKTsK KyAgICB7IAorICAgICAgY2hhciAqIG1zZzA7CisgICAgICBpZiAoRU9GX1JlYWNoZWQgJiYg d29yZF90b3A+PTApIHsKKyAgICAgICAgbXNnMCA9IChjaGFyICopIHhtYWxsb2MoMTI4KnNp emVvZihjaGFyKSk7CisgICAgICAgIHNwcmludGYobXNnMCwgInN5bnRheCBlcnJvcjogdW5l eHBlY3RlZCBlbmQgb2YgZmlsZSBmcm9tIGxpbmUgJWQuIiwgd29yZF9saW5lbm9bd29yZF90 b3BdKTsKKyAgICAgIH0gCisgICAgICAKKyAgICAgIC8qIGlmICh3b3JkX3RvcD49MCkgewor CW1zZyA9IEVPRl9SZWFjaGVkID8gXygic3ludGF4IGVycm9yOiB1bmV4cGVjdGVkIGVuZCBv ZiBmaWxlIGZyb20gbGluZSAlZC4iKSwgd29yZF9saW5lbm9bd29yZF90b3BdIDogXygic3lu dGF4IGVycm9yIik7CisgICAgICB9IGVsc2UgeworCW1zZyA9IEVPRl9SZWFjaGVkID8gXygi c3ludGF4IGVycm9yOiB1bmV4cGVjdGVkIGVuZCBvZiBmaWxlIikgOiBfKCJzeW50YXggZXJy b3IiKTsKKyAgICAgIH0qLworICAgICAgbXNnID0gRU9GX1JlYWNoZWQgPyBfKG1zZzApIDog Xygic3ludGF4IGVycm9yIik7CiAgICAgICBwYXJzZXJfZXJyb3IgKGxpbmVfbnVtYmVyLCAi JXMiLCBtc2cpOworICAgICAgeGZyZWUobXNnMCk7CiAgICAgICAvKiBXaGVuIHRoZSBzaGVs bCBpcyBpbnRlcmFjdGl2ZSwgdGhpcyBmaWxlIHVzZXMgRU9GX1JlYWNoZWQKIAkgb25seSBm b3IgZXJyb3IgcmVwb3J0aW5nLiAgT3RoZXIgbWVjaGFuaXNtcyBhcmUgdXNlZCB0bwogCSBk ZWNpZGUgd2hldGhlciBvciBub3QgdG8gZXhpdC4gKi8K --------------020000030903040400060307--