Thread overview
__stdin.d(2): Error: found End of File when expecting }
Jul 17, 2019
Andre Pany
Jul 17, 2019
H. S. Teoh
Jul 17, 2019
ag0aep6g
Jul 17, 2019
Andre Pany
July 17, 2019
Hi,

this scripts throws 2 times this error:
__stdin.d(2): Error: found End of File when expecting } following compound statement
__stdin.d(2): Error: found End of File when expecting } following compound statement

```
#!/bin/bash

text="
import std;

void main()
{
    while(true)
    {
        string enemy1 = readln().strip;
        int dist1 = to!int(readln().strip);

        string enemy2 = readln().strip;
        int dist2 = to!int(readln().strip);

        // Write an action using writeln()
        writeln(dist1 > dist2 ? enemy2 : enemy1);
        // Enter the code here
    }
}"

curl -fsS https://dlang.org/install.sh | bash -s dmd-2.087.0
source ~/dlang/dmd-2.087.0/activate
echo $text | dmd -
```

what is here wrong?
( I execute it using on Ubuntu 18.04 LTS using WSL)

Kind regards
André
July 17, 2019
On Wed, Jul 17, 2019 at 07:05:20PM +0000, Andre Pany via Digitalmars-d-learn wrote:
> Hi,
> 
> this scripts throws 2 times this error:
> __stdin.d(2): Error: found End of File when expecting } following compound
> statement
> __stdin.d(2): Error: found End of File when expecting } following compound
> statement

My first suspicion is that the shell is interpreting metacharacters in your string and thereby mangling it.


[...]
> ```
> #!/bin/bash
> 
> text="
> import std;
> 
> void main()
> {
>     while(true)
>     {
>         string enemy1 = readln().strip;
>         int dist1 = to!int(readln().strip);
> 
>         string enemy2 = readln().strip;
>         int dist2 = to!int(readln().strip);
> 
>         // Write an action using writeln()
>         writeln(dist1 > dist2 ? enemy2 : enemy1);
>         // Enter the code here
>     }
> }"
> 
> curl -fsS https://dlang.org/install.sh | bash -s dmd-2.087.0
> source ~/dlang/dmd-2.087.0/activate
> echo $text | dmd -
> ```
> 
> what is here wrong?
> ( I execute it using on Ubuntu 18.04 LTS using WSL)
> 
> Kind regards
> André

-- 
IBM = I'll Buy Microsoft!
July 17, 2019
On 17.07.19 21:05, Andre Pany wrote:

> ```
> #!/bin/bash
> 
> text="
> import std;
> 
> void main()
> {
>      while(true)
>      {
>          string enemy1 = readln().strip;
>          int dist1 = to!int(readln().strip);
> 
>          string enemy2 = readln().strip;
>          int dist2 = to!int(readln().strip);
> 
>          // Write an action using writeln()
>          writeln(dist1 > dist2 ? enemy2 : enemy1);
>          // Enter the code here
>      }
> }"
> 
> curl -fsS https://dlang.org/install.sh | bash -s dmd-2.087.0
> source ~/dlang/dmd-2.087.0/activate
> echo $text | dmd -
> ```
> 
> what is here wrong?

Check out what `echo $text` prints:

----
import std; void main() { while(true) { string enemy1 = readln().strip; int dist1 = to!int(readln().strip); string enemy2 = readln().strip; int dist2 = to!int(readln().strip); // Write an action using writeln() writeln(dist1 > dist2 ? enemy2 : enemy1); // Enter the code here } }
----

Note that it's all on one line. And remember that a "//"-style comment spans the rest of the line.

That's right. Everything after the first "//" is now part of the comment, all the way to the last closing brace. Obviously, that's not valid code anymore.

Try using double quotes around $text:

    echo "$text" | dmd -
July 17, 2019
On Wednesday, 17 July 2019 at 20:02:51 UTC, ag0aep6g wrote:
> On 17.07.19 21:05, Andre Pany wrote:
>
>> [...]
>
> Check out what `echo $text` prints:
>
> ----
> import std; void main() { while(true) { string enemy1 = readln().strip; int dist1 = to!int(readln().strip); string enemy2 = readln().strip; int dist2 = to!int(readln().strip); // Write an action using writeln() writeln(dist1 > dist2 ? enemy2 : enemy1); // Enter the code here } }
> ----
>
> Note that it's all on one line. And remember that a "//"-style comment spans the rest of the line.
>
> That's right. Everything after the first "//" is now part of the comment, all the way to the last closing brace. Obviously, that's not valid code anymore.
>
> Try using double quotes around $text:
>
>     echo "$text" | dmd -

Thanks a lot, that solved the issue.

Kind regards
Andre