Skip to content

Running F# scripts in unix without proper file extensions results in strange behaviour #1241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
eiriktsarpalis opened this issue Jun 3, 2016 · 5 comments
Labels
Area-FSI Bug help wanted Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@eiriktsarpalis
Copy link
Member

In any unix environment with F# 4.0 installed, running

echo '#!/usr/bin/env fsharpi\nprintfn "Hello, World!"' > hello
chmod +x hello
./hello

Results in the following behaviour:

[12:43] eirik@eudoxos: ~/devel> ./hello

F# Interactive for F# 4.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License

For help type #help;;

[Loading /home/eirik/devel/hello]


error FS0226: The file extension of '/home/eirik/devel/hello' is not recognized. Source files must have extension .fs, .fsi, .fsx, .fsscript, .ml or .mli.
>

While the error message clearly states what the problem is here, I think there are a couple of issues to notice:

  • It is common practice to omit file extensions in executables. Perhaps we should consider supporting this in the fsi context?
  • An invalid file extension will cause fsi to run in interactive mode, which seems a bit bizarre. It actually took me a while to understand what was going on because of all the text that was being output.
@eiriktsarpalis eiriktsarpalis changed the title Running F# scripts in unix without proper file extensions results in strange error messages Running F# scripts in unix without proper file extensions results in strange behaviour Jun 3, 2016
@KevinRansom KevinRansom added the Bug label Jun 6, 2016
@KevinRansom
Copy link
Member

@eiriktsarpalis
Yes I agree, restricting the extensions of files in this way is incorrect.

@eiriktsarpalis
Copy link
Member Author

@KevinRansom Do you think we should lift this restriction for fsi only or the compiler in general?

@dsyme
Copy link
Contributor

dsyme commented Jun 13, 2016

@eiriktsarpalis Just for FSI, and probably only for one script. I think the extension matters too much for the compiler, c.f. fs v. fsi v. fsx, shich all have different rules.

@dsyme dsyme added Area-Compiler Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Jul 11, 2016
@dsyme dsyme added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. and removed Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Nov 15, 2016
@cartermp cartermp added this to the Unknown milestone Aug 25, 2018
@cartermp cartermp modified the milestones: Unknown / not bug, Backlog May 23, 2019
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
@vzarytovskii vzarytovskii reopened this Jan 4, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in F# Compiler and Tooling Jan 4, 2024
@nodakai
Copy link

nodakai commented Apr 11, 2025

I tried installing an F# script to replace /usr/bin/sendmail (wanted to forward cron failure mails to webhooks) only to discover this restriction. i ended up installing a Bash wrapper which calls the .fsx script but I felt that was an unnecessary indirection.

I wouldn’t mind passing an extra argument like --extension fsx to dotnet fsi if that helps

@T-Gro
Copy link
Member

T-Gro commented Apr 11, 2025

If we speak of dotnet fsi only, the extension restriction could be lifted.
I will mark it as help wanted - if anyone is interested into contribution, feel free to reach out and discuss possibilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FSI Bug help wanted Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
Development

No branches or pull requests

7 participants