Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define a shell script using the c# lang (dotnet core runtime)?

Tags:

c#

linux

bash

shell

for example to define a script that print "hello".

I can do the following with nodejs (hello_node)

#!/bin/node
console.log(`hello ${process.argv[2]}`)

Then I will call it

./hello_node "world"

Also in Python

#!/bin/python3.7
print("hello world")

The same works in PHP and ruby, is there a way to do this in C# ?

I've tried the below, but it didn't work

#!/usr/local/share/dotnet/dotnet run
using System;

public static class Program {

  public static void Main(string[] args)
  {
    Console.WriteLine("Hello " + args[1]);
  }

}
like image 806
amd Avatar asked Mar 06 '26 02:03

amd


1 Answers

A shebang (#!) tells the it to open the file with a specific command.

The dotnet run command can only be used to run projects, not single files.

You could try using the dotnet-script tool, but you'd need to setup the directory which might be a big downside based on what you're trying to achieve

https://github.com/filipw/dotnet-script

like image 126
ikkentim Avatar answered Mar 08 '26 17:03

ikkentim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!