bash pipe fails in script with subshell/loop cmbination

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bash pipe fails in script with subshell/loop cmbination

Wouter van Doorn-2
Hi all,

I've run into a problem regarding pipes in bash, in a command that
loops. I've reduced it to a very small one-liner that fails. The two
versions below should, I'm sure, give the same output - but they
don't. I know the command is silly and useless as it is shown here,
but it's what I'm left with from something more complex after removing
as much of the complexity as I could while retaining the actual
problem I'm fighting.

ONE - this works as expected
$ for j in 1 2;do echo $j $(echo hello);done
1 hello
2 hello

TWO - this fails, apparently (warning: my guess) at the pipe
$ for j in 1 2;do echo $j $(echo hello | cat);done
1
2

THREE - To make it that bit more obscure, the following command also
works as it should, which by now I did not expect:
$ echo hello $(echo world | cat)
hello world

If 'cat' (in TWO) is replaced by 'od -a', then od does not generate
any output (at all) either. Can someone tell me what's wrong either in
what happens or in my expectation?

I have found someone on stackexchange who may, I think, be related
(https://unix.stackexchange.com/questions/364765/store-command-output-in-variable-when-command-includes-pipes)
but unfortunately that was not resolved. I tried it with virusscanning
switched off - no difference.

Thanks for looking!

Wouter van Doorn


--
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

cygcheck.txt (80K) Download Attachment
installed.db (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bash pipe fails in script with subshell/loop cmbination

Ronald Otto Valentin Fischer
>
> TWO - this fails, apparently (warning: my guess) at the pipe
> $ for j in 1 2;do echo $j $(echo hello | cat);done
> 1
> 2

This works for me:

$ for j in 1 2;do echo $j $(echo hello | cat);done
1 hello
2 hello

I have:

GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)

Ronald
--
Ronald Fischer <[hidden email]>
http://www.fusshuhn.de/

--
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bash pipe fails in script with subshell/loop cmbination

Ronald Fischer-6
In reply to this post by Wouter van Doorn-2
>
> TWO - this fails, apparently (warning: my guess) at the pipe
> $ for j in 1 2;do echo $j $(echo hello | cat);done
> 1
> 2

This works for me:

$ for j in 1 2;do echo $j $(echo hello | cat);done
1 hello
2 hello

I have:

GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)

Ronald

--
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bash pipe fails in script with subshell/loop cmbination

Eliot Moss
On 8/8/2017 10:20 AM, Ronald Fischer wrote:

>>
>> TWO - this fails, apparently (warning: my guess) at the pipe
>> $ for j in 1 2;do echo $j $(echo hello | cat);done
>> 1
>> 2
>
> This works for me:
>
> $ for j in 1 2;do echo $j $(echo hello | cat);done
> 1 hello
> 2 hello

It also works for me.  If it is not a version issue, then I
wonder about BLODA.  Maybe anti-virus or similar tools are
wrapping process creation in such a way that things get
confused.  Try cygcheck, etc.

Regards - EM

--
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: bash pipe fails in script with subshell/loop cmbination

Nellis, Kenneth (Conduent)
> From: Eliot Moss
> It also works for me.  If it is not a version issue, then I
> wonder about BLODA.  Maybe anti-virus or similar tools are
> wrapping process creation in such a way that things get
> confused.  Try cygcheck, etc.

BTW, it also works for me.

With so many Cygwin issues being attributed to BLODA, I wonder
if there is a reasonably small set of things that BLODA breaks
that could be tested in code, and that such a bloda-checking
program could be added to the package repertoire? (Of course,
SHTDI and, sadly, such a task is not in my skill set.)

--Ken Nellis

--
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bash pipe fails in script with subshell/loop cmbination

Achim Gratz
In reply to this post by Wouter van Doorn-2
Wouter van Doorn writes:
> I've run into a problem regarding pipes in bash, in a command that
> loops. I've reduced it to a very small one-liner that fails.

WJFFM.  Unless it's down (again) to your somewhat bizarre PATH settings,
you're most likely looking at some BLODA that tries to follow each
forked process and can't keep up at some point.


Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs

--
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bash pipe fails in script with subshell/loop cmbination

cyg Simple
In reply to this post by Nellis, Kenneth (Conduent)
On 8/8/2017 10:59 AM, Nellis, Kenneth wrote:
> SHTDI and, sadly, such a task is not in my skill set.)
>

Nothing like attempting to do it to add skills to your set.  This isn't
a valid reason not to do it.  It is only a valid reason that it would
take longer than someone else who might attempt it, assuming someone
else would even try for which there is no guarantee.  So if you want to
see this idea implemented, just do it.

--
cyg Simple

--
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

Loading...