standards/181240: /bin/sh choking on a certain construct
Jilles Tjoelker
jilles at stack.nl
Mon Aug 12 21:55:06 UTC 2013
On Mon, Aug 12, 2013 at 09:10:01PM +0000, Jens Schweikhardt wrote:
> The following reply was made to PR standards/181240; it has been noted
> by GNATS.
> From: Jens Schweikhardt <schweikh at schweikhardt.net>
> To: Tamas TEVESZ <ice at extreme.hu>
> Cc: freebsd-gnats-submit at FreeBSD.org
> Subject: Re: standards/181240: /bin/sh choking on a certain construct
> Date: Mon, 12 Aug 2013 23:06:43 +0200
> On Mon, Aug 12, 2013 at 01:54:02PM +0000, Tamas TEVESZ wrote:
> # >How-To-Repeat:
> # /bin/sh -c 'echo foo || >&2 | cat'
> #
> # (Or, if you have misc/mc installed, hit ^[3 on a .diff/.patch/.so etc. file for which mc calls /usr/local/libexec/mc/ext.d/misc.sh)
> A simpler invocation is
> $ >x | cat
> Syntax error: "|" unexpected
> If I read the SUS shell grammar correctly, a lone redirection cannot be
> a simple command in a pipe, so this is an extension that the other
> shells accept. I'm not sure if this is a particular useful extension.
I think the PR is valid. A lone redirection is a valid simple command,
everywhere a simple command may occur. In the grammar, the
simple_command consists of a single cmd_prefix which consists of a
single io_redirect.
I fixed this for & in 2010 and fixing it for | as well is not hard. The
same problem exists for ;; and ;&. See the below patch. I plan to commit
it soon.
Index: bin/sh/parser.c
===================================================================
--- bin/sh/parser.c (revision 253911)
+++ bin/sh/parser.c (working copy)
@@ -577,6 +577,9 @@ TRACE(("expecting DO got %s %s\n", tokname[got], g
case TSEMI:
case TAND:
case TOR:
+ case TPIPE:
+ case TENDCASE:
+ case TFALLTHRU:
/*
* An empty command before a ; doesn't make much sense, and
* should certainly be disallowed in the case of `if ;'.
Index: tools/regression/bin/sh/parser/only-redir2.0
===================================================================
--- tools/regression/bin/sh/parser/only-redir2.0 (revision 0)
+++ tools/regression/bin/sh/parser/only-redir2.0 (working copy)
@@ -0,0 +1,2 @@
+# $FreeBSD$
+</dev/null | :
Property changes on: tools/regression/bin/sh/parser/only-redir2.0
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Index: tools/regression/bin/sh/parser/only-redir3.0
===================================================================
--- tools/regression/bin/sh/parser/only-redir3.0 (revision 0)
+++ tools/regression/bin/sh/parser/only-redir3.0 (working copy)
@@ -0,0 +1,2 @@
+# $FreeBSD$
+case x in x) </dev/null ;; esac
Property changes on: tools/regression/bin/sh/parser/only-redir3.0
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Index: tools/regression/bin/sh/parser/only-redir4.0
===================================================================
--- tools/regression/bin/sh/parser/only-redir4.0 (revision 0)
+++ tools/regression/bin/sh/parser/only-redir4.0 (working copy)
@@ -0,0 +1,2 @@
+# $FreeBSD$
+case x in x) </dev/null ;& esac
Property changes on: tools/regression/bin/sh/parser/only-redir4.0
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
--
Jilles Tjoelker
More information about the freebsd-standards
mailing list