Thank you for creating and maintaining this project.
Problem
line.Parse parses and reprints the input with mvdan.cc/sh/v3/syntax, then calls shellquote.Split. As a result, unquoted backslashes are interpreted as shell escape characters.
For example:
is passed to Cobra as:
[]string{"ls", "C:WindowsTemp"}
instead of:
[]string{"ls", `C:\Windows\Temp`}
With the current parser, users must instead quote the entire value, as in ls 'C:\Windows\Temp', or escape every backslash, as in ls C:\\Windows\\Temp. Both forms work, but they are cumbersome when arguments are intended to be passed to Cobra literally.
If the value ends in a backslash, such as ls C:\Windows\Temp\, AcceptMultiline also treats the input as incomplete and waits for another line.
Quoting the value or doubling every backslash works, but is inconvenient when the console is used as a general Cobra frontend rather than as a shell.
Request
Would you consider exposing a configurable execution parser, or providing a mode that preserves literal backslashes?
The current shell-compatible behavior could remain the default. Applications should be able to select matching parsing and line-completeness semantics so that a trailing literal backslash is not always treated as a continuation marker.
cmd/internal/quoted.Split could be one
implementation option for a literal-backslash mode, although it is an internal package and
multiline detection would still need to be handled separately.
Thank you for creating and maintaining this project.
Problem
line.Parseparses and reprints the input withmvdan.cc/sh/v3/syntax, then callsshellquote.Split. As a result, unquoted backslashes are interpreted as shell escape characters.For example:
is passed to Cobra as:
instead of:
With the current parser, users must instead quote the entire value, as in
ls 'C:\Windows\Temp', or escape every backslash, as inls C:\\Windows\\Temp. Both forms work, but they are cumbersome when arguments are intended to be passed to Cobra literally.If the value ends in a backslash, such as
ls C:\Windows\Temp\,AcceptMultilinealso treats the input as incomplete and waits for another line.Quoting the value or doubling every backslash works, but is inconvenient when the console is used as a general Cobra frontend rather than as a shell.
Request
Would you consider exposing a configurable execution parser, or providing a mode that preserves literal backslashes?
The current shell-compatible behavior could remain the default. Applications should be able to select matching parsing and line-completeness semantics so that a trailing literal backslash is not always treated as a continuation marker.
cmd/internal/quoted.Splitcould be oneimplementation option for a literal-backslash mode, although it is an internal package and
multiline detection would still need to be handled separately.