diff --git a/include/execution.h b/include/execution.h index 7ca74a8..8265582 100644 --- a/include/execution.h +++ b/include/execution.h @@ -6,7 +6,7 @@ /* By: mmoussou cmd, X_OK) \ - && !is_in_builtins(cmd->cmd))) + if (exec.status == -1 || !input || check_file(cmd->cmd, input)) { - printf("minishell : command not found: %s$\n", input); + if (exec.status == -1) + printf("minishell : command not found: %s\n", input); free(input); return (-1); } diff --git a/src/exec/utils_exec.c b/src/exec/utils_exec.c index 45aa5bd..ab6e148 100644 --- a/src/exec/utils_exec.c +++ b/src/exec/utils_exec.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/09 19:25:18 by adjoly #+# #+# */ -/* Updated: 2024/07/10 01:17:11 by adjoly ### ########.fr */ +/* Updated: 2024/07/14 15:49:04 by mmoussou ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,3 +89,25 @@ int switch_cmd_path(t_cmd *cmd, t_env *env) return (-1); return (0); } + +int check_file(char *cmd, char *input) +{ + struct stat entry; + int status; + + if (is_in_builtins(cmd)) + return (0); + status = stat(cmd, &entry); + if (status) + { + printf("minishell : command not found: %s\n", input); + return (1); + } + if (!S_ISDIR(entry.st_mode) && !access(cmd, X_OK)) + return (0); + if (S_ISDIR(entry.st_mode)) + printf("minishell : %s is a directory.\n", input); + else + printf("minishell : command not found: %s\n", input); + return (1); +}