X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=OyxljhdrYxWlwqlW
	YvYWRG9v6DXrZE6CfxCvFzZxDE9e2S12+p4aCs+N8n2V35WRVmJiDDU2ucDIOCwy
	0u5/eWK2bZXcTyY2T6lr5sEVXRc8FQXUY0i2tRfvwiRsBzrPneAktw0/ssePSstT
	uE8us+I0wGZKeUYkFYsfhVEYnig=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=auvPtbF3j7dZZ7b4p2cGC6
	Pzc2I=; b=lqFbbqF/RnHf2TEgpsWuWYlShYL/uPM+nt/WbvJwGCReuo3QNezSBN
	23/iiORiH4+/yRRtdqgxPQdxZGgfXzqLWh1dBAZWZHQ/H4813VjPIS8TWYfirW1u
	Rrg1rT4+CaO/PfRRzQdXeXgPEHeyrcHmMT8jqSJn0YFQKGxZzgaZc=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=Enterprise, txt, edition, realise
X-HELO: mail-wm0-f53.google.com
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=1e100.net; s=20130820;        h=x-gm-message-state:subject:to:references:from:message-id:date         :user-agent:mime-version:in-reply-to:content-transfer-encoding;        bh=Uyk2ialp32o9fDYPYuV/cXRC+KRJXlLqHsRHuEhf9oE=;        b=L6axjHydEukeFh0iAaxvSyFY9tOfcn27Aok9PaCp62lPs0ISlEvVRUJJrOd4XESxeY         k0ULmPydAteqsk86af9I15HLlEJ0j6PvzWNUsU482R2u74FBc1Xojdp61oM9l70qumrh         M9BU8cZLm5bxBi8wMXwh020qDKHo2HdpnfnTJib4BL1Ip0NxzcQxPYdpfcG3ElkJImgd         LHhXagCWTpa79f8jvT5Rf2PM7rJw0uclZJe4Lpr4ghvxubMpNU9FpXIFOvtF7pso8grV         v4QYCcQEdNqjMGSTUDcYuqEFtiIUtoX+59ar3aWYHHY0vFcNmvadTATR9sReMP1/3I7M         M5Dg==
X-Gm-Message-State: AD7BkJJUXMddFVsBv0aa15BXMA1olxpy0vIpW6/8G80Dm0YADc5TDk2lEGg6tt58qr4Ckg==
X-Received: by 10.194.123.131 with SMTP id ma3mr8996811wjb.107.1456643966922;        Sat, 27 Feb 2016 23:19:26 -0800 (PST)
Subject: Re: echo -n or sleep 0 needed to unblock Bourne shell script
To: cygwin@cygwin.com
References: <DUB115-W24F35C271121BE1811952E8AB80@phx.gbl>
From: Marco Atzeri <marco.atzeri@gmail.com>
Message-ID: <56D29F78.1040609@gmail.com>
Date: Sun, 28 Feb 2016 08:19:20 +0100
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
MIME-Version: 1.0
In-Reply-To: <DUB115-W24F35C271121BE1811952E8AB80@phx.gbl>
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes

On 27/02/2016 23:28, Matthijs Nescio wrote:
> Hi,
>
> Sorry for replying in a new thread.
>
>          Hi,
>
>          I have the strangest problem. I am running some complicated advanced Bourne shell scripting. These scripts work fine under Ubuntu 14.04 LTS. However, in Cygwin I have to add some strange commands with no obvious effect; without these the scripts just hang. I can not disclose the scripts completely because they are company property. I realise that this does not comply to the rules of smart questions, but if anybody else has this problem the Cygwinners need to know about it. I do not exactly know when these problems started. I reinstalled Cygwin twice, several weeks ago and yesterday evening (25-2-2016).
>
>          I have had this problem with several complicated, lengthy scripts. Debugging using echo debug statements is hard because the echo makes the problem go away. When I discovered similar problems in multiple scripts, I reinstalled Cygwin, but the problem persists. Also rebooting my Windows 7 Enterprise edition machine does not solve the problem. I have had some experienced colleagues to look at this and they were as flabbergasted as I was.
>
>          Examples:
>
>             TTP_FILE_DR_KML=`echo $TTP_FILE.dr.kml | sed -s 's#\.txt\.#\.#g'`
>             #echo -n> /dev/null
>             sleep 0
>             if [ "`convert_needed "$TTP_FILE_DR_KML"`" = "convert" ]
>             then
>
>          In the examples above and below, either the sleep or the echo has to be commented in, otherwise the script just hangs. In the example below the doit function needs the echo or sleep, otherwise it does not return.
>
>          doit()
>          {
>             # 8< code removed
>             #echo -n
>             sleep 0
>          }
>

>
> The explaination of the issue may not be clear. I have to add the sleep 0 or the echo in order to keep my scripts running. Without these the scripts hang. Sometimes they can be interrupted by CTRL-C, sometimes they do not respond. The doit() function fails to end all together without the sleep. So the sleep 0 was not there before, it is needed for the flow of the script all of a sudden.
>
> Obviously, if adding an echo to a script changes the behaviour, it is kind of hard to prove that an empty echo has an effect. Again, I showed it to two colleagues who were surprised too. Together there was over 30 years of Bourne shell experience looking at the problem.
>
> The script containing the doit function is single-threaded, so there is no race condition in the script. Actually, it should just end itself after the curly brace. Without either the sleep or the echo it just hangs. Note also that the reproducibility is 100%, which is not expected from a race condition of marginal time differences. With reproducibility here I mean: adding the sleep/echo gives the normal flow, removing the sleep/echo gives a hanging script.
>
> Questions:
> * Were there changes in the Bourne shell interpreter in 2015/2016?

see the announcements
https://www.cygwin.com/ml/cygwin-announce/

I suspect the list is very long.

> * Are these interpreters well-tested for regression?

Yes.

> * Are similar issues reported?

Not that I personally remember.

> Thank you, kind regards, Matthijs.
>

I misunderstood your first explanation.
So the script hang if you don't add one of the two commands.


 >          doit()
 >          {
 >             8< code removed
 >             #echo -n
 >             #sleep 0
 >          }

more than bash, the output redirection or the piping is a
likely source of hang.

For example this command serie, works differently on
cygwin than on Linux

   echo "prova" > prova.txt
   cat prova.txt
   cat prova.txt > prova.txt
   cat prova.txt

I suspect something similar is happening in your case and it is not
due to bash.

Regards
Marco





--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

