Skip to content

escapePosixShCommandArg

escapePosixShCommandArg(expr): string

Defined in: command/escape-posix-sh-command-arg.ts:21

Escape a string to be safely used as a shell argument in POSIX-compliant shells

It adds single quotes around a string and quotes/escapes any existing single quotes.

Example:

const unsafe = "It's a test";
const safe = escapeShellArgPosix(unsafe);
console.log(safe); // 'It'\''s a test'

string

The string to escape

string

The escaped string