If you want a more... ergonomic language, you can also use the new "run file directly" functionality in .NET 10. It supports shebangs directly and it will even install packages referenced in the script!
#!/usr/bin/env dotnet run
#:package [email protected]
using Newtonsoft.Json;
Console.WriteLine(
JsonConvert.SerializeObject(new { Hello = "world" })
);
Even better, with the #:sdk directive, you can even serve a tiny web app directly from your "fancy shell script"... #!/usr/bin/env dotnet run
#:sdk Microsoft.NET.Sdk.Web
WebApplication
.Create()
.MapGet("/", () => "Hello from a shell script!")
.Run();
I wrote my first one of these today (making a tool for agents in a c# codebase). Pretty good experience, though AOT does still have some rough edges.