What potential security risks are involved in using system() function in PHP to call shell scripts?

Using the system() function in PHP to call shell scripts can pose security risks such as command injection attacks if user input is not properly sanitized. To mitigate this risk, it is recommended to use escapeshellarg() function to escape any user input before passing it to the system() function.

$user_input = $_POST['user_input'];
$escaped_input = escapeshellarg($user_input);
system('your_script.sh ' . $escaped_input);