Skip to content

escapePosixShCommand

escapePosixShCommand(cmd): string

Defined in: command/escape-posix-sh-command.ts:19

Escapes any characters in a string that might be used to trick a POSIX-compliant shell command into executing arbitrary commands.

It escapes the following characters by adding a backslash before them: &#;`|*?~<>^()[]{}$, \n and \xFF.

The characters ' and " are escaped only if they are not paired.

Based on PHP escapeshellcmd: https://www.php.net/manual/en/function.escapeshellcmd.php

Source code: https://github.com/php/php-src/blob/d85662d6cc2c6d5f69403f6fb2001ff78e1bd174/ext/standard/exec.c#L270

string

The command to escape

string

The escaped command