mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
simple_cmd executing: print error message on command not found
This commit is contained in:
parent
a4c482e8f9
commit
66ea1328aa
2 changed files with 19 additions and 1 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
|
||||
/* Updated: 2025/03/27 18:32:18 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/28 16:56:47 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -32,6 +32,12 @@ static char **argv_from_wordlist(t_wordlist *wordlist)
|
|||
return (out);
|
||||
}
|
||||
|
||||
static void command_not_found(t_simple_cmd *cmd)
|
||||
{
|
||||
ft_dprintf(STDERR_FILENO, "minishell: %s: command not found\n",
|
||||
cmd->words->word->word);
|
||||
}
|
||||
|
||||
void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
char *exe;
|
||||
|
|
@ -41,7 +47,10 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
|||
return ;
|
||||
exe = get_cmdpath(cmd->words->word->word, app);
|
||||
if (exe == NULL)
|
||||
{
|
||||
command_not_found(cmd);
|
||||
return ;
|
||||
}
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
execve(exe, argv_from_wordlist(cmd->words), envp_from_env(app->env));
|
||||
|
|
|
|||
9
test.sh
9
test.sh
|
|
@ -134,6 +134,15 @@ single file:
|
|||
t
|
||||
EOF
|
||||
|
||||
when_run <<EOF "unknown commands"
|
||||
qwertyuiop
|
||||
poiuytrewq
|
||||
EOF
|
||||
expecting <<EOF
|
||||
minishell: qwertyuiop: command not found
|
||||
minishell: poiuytrewq: command not found
|
||||
EOF
|
||||
|
||||
when_run <<EOF "quoted parentheses are not operators"
|
||||
echo unclosed '('
|
||||
EOF
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue