quoteForSyntax function

String quoteForSyntax(
  1. String s,
  2. CommandSyntax syntax
)

s quoted as one argument for a shell of syntax: single quotes for a POSIX shell or PowerShell (each with its own escape), double quotes for cmd (which takes single quotes literally; Windows names hold no ").

Implementation

String quoteForSyntax(String s, CommandSyntax syntax) => switch (syntax) {
  CommandSyntax.powershell => "'${s.replaceAll("'", "''")}'",
  CommandSyntax.windowsCmd => '"${s.replaceAll('"', '')}"',
  _ => posixQuote(s),
};