Skip to content

Enhanced shebang #\!/usr/bin/dotnet fails when script is executed with arguments #9985

@StevenTCramer

Description

@StevenTCramer

Description

The enhanced shebang support introduced in .NET 10 Preview 6 works when executing a script without arguments, but fails when the script is executed with arguments.

Reproduction Steps

  1. Create a C# script file test.cs with the following content:
#\!/usr/bin/dotnet

Console.WriteLine("Args: " + string.Join(", ", args));
  1. Make it executable: chmod +x test.cs

  2. Execute without arguments (works):

./test.cs
# Output: Args: 
  1. Execute with arguments (fails):
./test.cs arg1 arg2
# Error: Could not execute because the specified command or file was not found.
# Possible reasons for this include:
#   * You misspelled a built-in dotnet command.
#   * You intended to execute a .NET program, but dotnet-./test.cs does not exist.
#   * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

Expected behavior

The script should execute successfully with arguments, similar to how #\!/usr/bin/dotnet run works.

Actual behavior

The script fails with an error suggesting that dotnet is trying to execute dotnet-./test.cs instead of properly handling the shebang.

Configuration

  • .NET SDK Version: 10.0.100-preview.6.25358.103
  • OS: Linux (WSL2)
  • Architecture: x64

Other information

This issue is particularly problematic when scripts are executed through process launchers like CliWrap, which is commonly used in build tools and test frameworks.

The workaround is to use #\!/usr/bin/dotnet run instead, which works correctly with arguments.

Related documentation: https://github.com/dotnet/core/blob/main/release-notes/10.0/preview/preview6/sdk.md#enhanced-shebang-support

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelNo area label was automatically applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions