question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shebang not working with runtime directive in script file

See original GitHub issue

I’m trying to play around with using these scripts, and I’m attempting to allow the file to be run directly from the terminal, however whenever I use the shebang and runtime directive together, I get the following error message:

test.csx(2,1): error CS1024: Preprocessor directive expected

I’m using the following script:

#! /usr/bin/env dotnet script
#! "netcoreapp2.1"

Console.WriteLine("Hello world");

If I remove the runtime directive, using ./test.csx works fine, and if it remove the shebang instead, then dotnet script test.csx works fine, it’s just when both are present, dotnet script seems to not like it. I’ve tried putting the shebang in with double quote around it, but then dotnet script just tries to load that as a runtime, and it doesn’t seem to work out.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
seesharpercommented, May 31, 2018

We should maybe consider scaffolding the shebang on *nix. We already set up the omnisharp.json during dotnet script init so OmniSharp will be happy either way

0reactions
tomlmcommented, Sep 26, 2018

#345 is new PR for this (I messed up the branch for #341. 2 things to make shebang work:

  1. just add the single directive !#/usr/bin/env dotnet-script
  2. mark the file as executable with chmod +x foo.csx
  3. make sure file doesn’t have Byte Order Mark (BOM) and has Linux LF, not windows

That works even without the PR. The PR is simple to make the Dotnet script init scaffolding do that by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shebang not working with runtime directive in script file #306
I'm trying to play around with using these scripts, and I'm attempting to allow the file to be run directly from the terminal, ......
Read more >
How to Use the Shebang in Bash and Python | Linode Docs
A Shebang directive, which always begins with the sequence #! , can sometimes be found on the first line of a Bash or...
Read more >
windows - Python shebang not working
The next problem is that the shebang is not implemented by the windows command shell. It works on linux shells (and linux-like shells...
Read more >
Does the shebang determine the shell which runs the script?
When the shebang is present, exec() will run the executable specified after the shebang instead. Note that this means that if you invoke...
Read more >
Shebang - Linux Bash Shell Scripting Tutorial Wiki
Starting a Script With #!. It is called a shebang or a "bang" line. It is nothing but the absolute path to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found