escapeShell function

String escapeShell(
  1. String text
)

Escape a string for safe use in shell commands.

Implementation

String escapeShell(String text) {
  if (text.isEmpty) return "''";
  if (RegExp(r'^[a-zA-Z0-9._/=-]+$').hasMatch(text)) return text;
  return "'${text.replaceAll("'", "'\\''")}'";
}