What potential security risks are involved in executing shell scripts with PHP?

Executing shell scripts with PHP can pose security risks such as command injection vulnerabilities if user input is not properly sanitized. To mitigate this risk, it is essential to validate and sanitize any user input before using it to execute shell commands.

$script = "script.sh";
$validated_input = escapeshellarg($user_input);
$output = shell_exec("sh $script $validated_input");