Quote one argument so the given shell passes it to the command intact.
POSIX shells: single quotes; an embedded ' becomes '\''. An argument
with nothing the shell would read is returned as is.
cmd.exe: every argument is escaped for the command's argv parser
(the MSVCRT / CommandLineToArgvW rules: wrapped in ", an embedded
" becomes \", and the backslashes before a " or the end double),
then every cmd.exe metacharacter, the quotes included, gets a ^. This
is cross-spawn's escapeArgument (lib/util/escape.js), after
qntm.org/cmd. cmd.exe expands %name%
before it reads carets, so a caret can't stop it: an escaped %PATH%
leaves the name PATH^, which no ordinary variable has, but
%name:old=new% and %name:~n,m% act on name alone. The argument
(or argv) throws where such an edit could expand (two % enclosing a
: with no caret before it), and for a line break, which ends a
cmd.exe command. A command name is bare when plain, else in real
quotes, and throws if it holds ", % or a line break. Not covered: a
variable whose name contains ^; !name! when delayed expansion is
turned on in the registry (off by default); and a batch file (.cmd,
.bat), which parses its arguments again.
PowerShell (powershell.exe, pwsh 7.3 or later): every argument is a
single-quoted string, so PowerShell reads nothing in it. Each character
PowerShell takes as a single quote (' and the curly quotes U+2018 to
U+201B) is doubled. The argument --% is passed as @('--%'):
PowerShell takes any argument whose value is --%, quoted or not, as
its stop-parsing marker, and an array holding it is passed as text.
Windows PowerShell 5.1 hands a native command its argument text without
escaping embedded double quotes, so for powershell.exe the argument
text is first escaped for the command's own argv parser.
An empty argument is kept: '' (POSIX, pwsh), "" (cmd.exe), or
'""' for powershell.exe, which drops an empty native argument.
Quote one argument so the given shell passes it to the command intact.
'becomes'\''. An argument with nothing the shell would read is returned as is.cmd.exe: every argument is escaped for the command's argv parser (the MSVCRT /CommandLineToArgvWrules: wrapped in", an embedded"becomes\", and the backslashes before a"or the end double), then every cmd.exe metacharacter, the quotes included, gets a^. This is cross-spawn'sescapeArgument(lib/util/escape.js), after qntm.org/cmd. cmd.exe expands%name%before it reads carets, so a caret can't stop it: an escaped%PATH%leaves the namePATH^, which no ordinary variable has, but%name:old=new%and%name:~n,m%act onnamealone. The argument (or argv) throws where such an edit could expand (two%enclosing a:with no caret before it), and for a line break, which ends a cmd.exe command. A command name is bare when plain, else in real quotes, and throws if it holds",%or a line break. Not covered: a variable whose name contains^;!name!when delayed expansion is turned on in the registry (off by default); and a batch file (.cmd,.bat), which parses its arguments again.powershell.exe,pwsh7.3 or later): every argument is a single-quoted string, so PowerShell reads nothing in it. Each character PowerShell takes as a single quote ('and the curly quotes U+2018 to U+201B) is doubled. The argument--%is passed as@('--%'): PowerShell takes any argument whose value is--%, quoted or not, as its stop-parsing marker, and an array holding it is passed as text. Windows PowerShell 5.1 hands a native command its argument text without escaping embedded double quotes, so forpowershell.exethe argument text is first escaped for the command's own argv parser.An empty argument is kept:
''(POSIX,pwsh),""(cmd.exe), or'""'forpowershell.exe, which drops an empty native argument.