Skip to main content

Function: escapeShellArg()

escapeShellArg(arg): string

Defined in: packages/core/src/utils/shell-security.ts:109

Escape a string for safe use as a shell argument

Wraps in single quotes and escapes any single quotes within. This is the safest way to pass arbitrary strings to shell commands.

Parameters

arg

string

The argument to escape

Returns

string

Escaped argument safe for shell interpolation

Example

const filename = "user's file.txt";
const escaped = escapeShellArg(filename);
// Returns: 'user'\''s file.txt'