dspinellis / dgsh

Shell supporting pipelines to and from multiple processes
http://www.spinellis.gr/sw/dgsh/
Other
323 stars 22 forks source link

Consider eliminating the need for a & operator #73

Closed dspinellis closed 7 years ago

dspinellis commented 7 years ago

Can't commands within a multipipe block be executed asynchronously by default? This is what happens in linear pipes and bash's process substitution. Is there ever a case for synchronous execution?

mfragkoulis commented 7 years ago

Fixed in https://github.com/dspinellis/dgsh/commit/1a204066f404daa6a7afd5319f6e68c86d03409d

Please note that newline is now treated as an operator for distinguishing commands (with unrelated IO) in a multipipe block. This is required in order to maintain an unambiguous grammar.

For example, this simple script:

{{
    echo hi &
    echo there &
}} |
cat

becomes

{{
    echo hi
    echo there
}} |
cat

where echo hi, echo there, and }} must be in different lines. Otherwise a syntax error will occur.

dspinellis commented 7 years ago

Something must be wrong in the way {{ is treated. Syntactically it should have the same treatment as {.

[dds@stereo dgsh]$ {{
> echo hi
> echo there
> }} | paste
hi      there
[dds@stereo dgsh]$ { echo hi ; echo there ; } | paste
hi
there
[dds@stereo dgsh]$ {{ echo hi ; echo there ; }} | paste
dgsh: syntax error near unexpected token `;'
mfragkoulis commented 7 years ago

As the commit states, commands in a multipipe block run asynchronously. Therefore the newline operator (\n) and the semicolon connector (;) adhere to the semantics of the multipipe block when used in it, that is, they signify asynchronous execution. The default connector for async execution in Bash (&) can also be used.

For example, the four following scripts are equivalent:

{{
    echo hi &
    echo there &
}} |
cat
{{
    echo hi
    echo there
}} |
cat
{{ echo hi ; echo there ; }} | cat
{{ echo hi & echo there & }} | cat