September 08, 2023

Good afternoon,

I finally got shebang work on a d file on my windows computer.
As a starter:

$ which rdmd
/c/Program Files/D/dmd2/windows/bin/rdmd

So, i put it in my main.d file as:

#!/c/Program Files/D/dmd2/windows/bin/rdmd
import std.stdio;
void main()  {
    writeln("Hello World!");
}

But a space in the shebang path is not a good idea:

$ ./main.d
bash: ./main.d: ./c/Program: bad interpreter: No such file or directory

According to https://lists.gnu.org/archive/html/bug-bash/2008-05/msg00052.html this is normal behavior. Be it. I created a sim link in the directory where my main.d file is:

$ ln -s /c/Program Files/D/dmd2/windows/bin/rdmd rdmd

And modified my file accordingly:

#!./rdmd
import std.stdio;
void main()  {
    writeln("Hello World!");
}

And now:

$ ./main.d
Hello World!

Note that I did not put the --shebang option on the shebang line. IF I do so:

$ ./main.d
Error: unrecognized switch '--shebang'
       run `dmd` to print the compiler manual
       run `dmd -man` to open browser on manual
Failed: ["dmd", "--shebang", "-v", "-o-", "./main.d", "-I."]

Hmm.. Is this a deprecated option? When i run rdmd --help, it is still here:

$ rdmd --help
...
--shebang          rdmd is in a shebang line (put as first argument)
...

What would be the purpose of this --shebang option?