shellQuote function

String shellQuote(
  1. String value
)

Quotes value for a POSIX shell, leaving plain words unquoted.

Implementation

String shellQuote(String value) {
  if (value.isEmpty) {
    return "''";
  }
  if (RegExp(r'^[A-Za-z0-9_@%+=:,./-]+$').hasMatch(value)) {
    return value;
  }
  return "'${value.replaceAll("'", "'\"'\"'")}'";
}