sdk: *nix: dotnet subcommands incorrectly splitting quoted args containing spaces

Steps to reproduce

To see problem, use this:

using System;

class Program
{
    static void Main(string[] args)
    {
        for(var i = 0; i < args.Length; i++)
        {
            Console.WriteLine($"{i} = {args[i]}");
        }
    }
}

Execute dotnet run a b '" c "' d

Expected behavior

Output should be:

0 = a
1 = b
2 = " c "
3 = d

Actual behavior

0 = a
1 = b
2 = "
3 = c
4 = "
5 = d

Environment data

Repros in preview2 and preview3 nightlies, bash on Linux and OSX

dotnet --info output:

.NET Command Line Tools (1.0.0-preview3-003546)

Product Information:
 Version:            1.0.0-preview3-003546
 Commit SHA-1 hash:  c0c07ed959

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  14.04
 OS Platform: Linux
 RID:         ubuntu.14.04-x64

More info

The problem appears to be somewhere in CLI. Using dotnet exec does not have this problem.

namc@ubuntu:/tmp/quoted$ dotnet exec --depsfile bin/Debug/netcoreapp1.0/quoted.deps.json --runtimeconfig bin/Debug/netcoreapp1.0/quoted.runtimeconfig.json bin/Debug/netcoreapp1.0/quoted.dll a b '" c "' d
0 = a
1 = b
2 = " c "
3 = d

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

The issue on Arch Linux is how dotnet is being packaged.

It’s installing .NET Core into a non-standard location of /opt/dotnet/dotnet and then using a shell script at /usr/bin/dotnet to invoke /opt/dotnet/dotnet after setting DOTNET_ROOT to point at /opt/dotnet/dotnet. This shell script does not preserve the quotes when forwarding the arguments to /opt/dotnet/dotnet.

Possible workarounds:

  • Use /opt/dotnet/dotnet to invoke (e.g. /opt/dotnet/dotnet run foo "bar baz").
  • Edit /usr/bin/dotnet and change $@ to "$@" to preserve the quotes.

An issue should be filed with the Arch Linux bug tracker for the community/dotnet-host package regarding fixing the /usr/bin/dotnet wrapper script.

Hi @Vogel612,

I’m unable to reproduce this issue with either 2.2.100 or 2.2.101 (the most recent SDK version), at least on macOS. Unfortunately I’m far away from my Arch system (which is powered down), but I can try to reproduce it in a VM if you like.

The fix should have made it into 2.1.300 and I see it tagged all the way through to the current release.

reported against the arch bugtracker as https://bugs.archlinux.org/task/61427

I’m currently encountering this issue on ArchLinux using zsh, bash and sh. dotnet --info puts me at version 2.2.100 for the sdk and 2.2.0 for the host version.

 dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.100
 Commit:    b9f2fa0ca8

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /opt/dotnet/sdk/2.2.100/

Host (useful for support):
  Version: 2.2.0
  Commit:  1249f08fed

.NET Core SDKs installed:
  2.2.100 [/opt/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.NETCore.App 2.2.0 [/opt/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Using the 3.0.100-preview-009752 fixes the issue.