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' Copy
const unsafe = "It's a test";const safe = escapeShellArgPosix(unsafe);console.log(safe); // 'It'\''s a test'
The string to escape
The escaped string
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: