fix(command_not_found): unset or empty PATH leads to No such file or directory error

This commit is contained in:
Khaïs COLIN 2025-04-25 15:36:59 +02:00
parent c756d3783f
commit 29bbb5e572
4 changed files with 48 additions and 6 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
/* Updated: 2025/04/22 15:38:00 by khais ### ########.fr */
/* Updated: 2025/04/25 15:47:14 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,11 +28,23 @@
#include "../../postprocess/expansion/expand_wildcard.h"
#include "simple_cmd_execute_debug.h"
#include "handle_redirections.h"
#include "../../subst/simple_filename_exp_utils_utils.h"
#include "../../subst/path_split.h"
static void command_not_found(t_simple_cmd *cmd, t_minishell *app)
{
ft_dprintf(STDERR_FILENO, "minishell: %s: command not found\n",
cmd->words->word->word);
char **path;
path = get_paths_array(app->env);
if (path == NULL || path[0] == NULL)
{
ft_dprintf(STDERR_FILENO, "minishell: %s: No such file or directory\n",
cmd->words->word->word);
}
else
ft_dprintf(STDERR_FILENO, "minishell: %s: command not found\n",
cmd->words->word->word);
path_split_destroy(path);
app->last_return_value = 127;
}