What are potential pitfalls of calling a .SH file using PHP?

Potential pitfalls of calling a .SH file using PHP include security vulnerabilities if the input is not properly sanitized, as it could lead to command injection attacks. To solve this issue, it is important to validate and sanitize user inputs before passing them to the shell_exec function in PHP.

<?php
// Validate and sanitize user input
$filename = filter_var($_POST['filename'], FILTER_SANITIZE_STRING);

// Call the .SH file using shell_exec after sanitizing the input
$output = shell_exec("./$filename.sh");

// Output the result
echo $output;
?>