What are the potential pitfalls of using the system function in PHP to execute shell commands?

Using the system function in PHP to execute shell commands can pose security risks, as it allows for arbitrary commands to be executed on the server. To mitigate this risk, it is recommended to use escapeshellarg() or escapeshellcmd() to escape any user input before passing it to the system function.

$user_input = $_POST['input']; // assuming user input is coming from a form field

$escaped_input = escapeshellarg($user_input); // escape user input

system("command " . $escaped_input); // execute command with escaped input