From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jilles Tjoelker Subject: Re: heredoc and subshell Date: Wed, 24 Feb 2016 00:18:44 +0100 Message-ID: <20160223231843.GA55161@stack.nl> References: <2978711456265264@web9h.yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from relay02.stack.nl ([131.155.140.104]:57980 "EHLO mx1.stack.nl" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751740AbcBWX21 (ORCPT ); Tue, 23 Feb 2016 18:28:27 -0500 Content-Disposition: inline In-Reply-To: <2978711456265264@web9h.yandex.ru> Sender: dash-owner@vger.kernel.org List-Id: dash@vger.kernel.org To: Oleg Bulatov Cc: dash@vger.kernel.org On Wed, Feb 24, 2016 at 01:07:44AM +0300, Oleg Bulatov wrote: > trying to minimize a shell code I found an unobvious moment with > heredocs and subshells. > Is it specified by POSIX how next code should be parsed? dash output > for this code differs from bash and zsh. > --- code > prefix() { sed -e "s/^/$1:/"; } > DASH_CODE() { :; } > > prefix A < echo line 1 > XXX > echo line 2)" && prefix DASH_CODE < echo line 3 > XXX > echo line 4)" > echo line 5 > DASH_CODE > --- bash 4.3.42 output: > A:echo line 3 > B:echo line 1 > line 2 > DASH_CODE:echo line 4)" > DASH_CODE:echo line 5 > --- dash 0.5.8 output: > A:echo line 1 > B:echo line 2)" && prefix DASH_CODE < B:echo line 3 > line 4 > line 5 I think POSIX is clear that the bash/zsh behaviour is correct and the dash behaviour is wrong. In XCU 2.6.3 Command Substitution, it says: ] With the $(command) form, all characters following the open ] parenthesis to the matching closing parenthesis constitute the ] command. Therefore, the shell should not start reading the here-document belonging to prefix A <