2 2

Commands in brace group are not correctly piped

Tudor Roman
Details
Message ID
<9a1b068d-8bbf-577c-9a53-14a565bf3fb0@gmail.com>
Sender timestamp
1557824269
DKIM signature
pass
Download raw message
Script example:

#!/usr/bin/env mrsh

{

     echo test1

     echo test2

} | lolcat

Expected output: "test1" and "test2" should appear on consecutive lines 
in rainbow colors.

Actual output: "test2" appears before "test1", and only "test1" is 
rainbow colored.

If you add more echo's, only the first will be rainbow colored.

Bonus, if you write the brace expansion on one line, with a pipe at the end:

{ echo test1; echo test2; } | lolcat

You'll get a nice assertion error:

mrsh: ../mrsh/shell/job.c:130: _Bool job_set_foreground(struct mrsh_job *, _Bool, _Bool): Assertion `state->foreground_job == NULL' failed.
mrsh: ../mrsh/shell/job.c:130: _Bool job_set_foreground(struct mrsh_job *, _Bool, _Bool): Assertion `state->foreground_job == NULL' failed.
zsh: abort (core dumped)  mrsh

--

Tudor Roman
Tudor Roman
Details
Message ID
<d0b64359-343f-2924-e9d3-0d0497170f84@gmail.com>
In-Reply-To
<9a1b068d-8bbf-577c-9a53-14a565bf3fb0@gmail.com> (view parent)
Sender timestamp
1557824328
DKIM signature
pass
Download raw message
*brace group, not brace expansion. sorry.
Details
Message ID
<dUrCXSoiHZmSf26JxninmLstewbuc5YWU4nIFUtaaRVa2sRT-_Ycnt9v1dFxR6n5RNK8d3RgmgBddBs3b6HSVNN4EXmllwvt3_WM8zlW4Go=@emersion.fr>
In-Reply-To
<d0b64359-343f-2924-e9d3-0d0497170f84@gmail.com> (view parent)
Sender timestamp
1558034286
DKIM signature
pass
Download raw message
> Script example:
>
> #!/usr/bin/env mrsh
>
> {
>
>      echo test1
>
>      echo test2
>
> } | lolcat
>
> Expected output: "test1" and "test2" should appear on consecutive lines
> in rainbow colors.
>
> Actual output: "test2" appears before "test1", and only "test1" is
> rainbow colored.
>
> If you add more echo's, only the first will be rainbow colored.
>
> Bonus, if you write the brace expansion on one line, with a pipe at the end:
>
> { echo test1; echo test2; } | lolcat
>
> You'll get a nice assertion error:
>
> mrsh: ../mrsh/shell/job.c:130: _Bool job_set_foreground(struct mrsh_job *, _Bool, _Bool): Assertion `state->foreground_job == NULL' failed.
> mrsh: ../mrsh/shell/job.c:130: _Bool job_set_foreground(struct mrsh_job *, _Bool, _Bool): Assertion `state->foreground_job == NULL' failed.
> zsh: abort (core dumped)  mrsh

Indeed, these are two bugs. Can you open two issues for those?

About the first one: we setup the pipeline redirections correctly [1] but when
the second command is started STDOUT_FILENO is no longer the FD we want (we
restore its previous value after the first command has been started).

This is a little bit annoying, maybe we need to add I/O redirections to the
context. I can't think of something else right now.

About the second one: I think `echo test2` isn't properly added to the job. Once
again this is a context issue. I think it gets reset by the time the second
command is started.

Anyway, thanks for spotting this!

[1]: https://github.com/emersion/mrsh/blob/master/shell/task/pipeline.c#L68