What is the potential risk of using the exec function in PHP to run commands with URLs?

Using the exec function in PHP to run commands with URLs can pose a security risk as it allows for command injection attacks. To mitigate this risk, it is important to sanitize and validate any user input before passing it to the exec function. This can help prevent malicious commands from being executed on the server.

$url = "https://example.com";
$validated_url = escapeshellarg($url);
exec("command $validated_url");