fix(exec/and or): was exiting too soon

This commit is contained in:
Khaïs COLIN 2025-04-25 17:51:54 +02:00
parent 7a5e838fcf
commit f0f19c3c0a
2 changed files with 55 additions and 5 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/07 10:38:55 by khais #+# #+# */ /* Created: 2025/04/07 10:38:55 by khais #+# #+# */
/* Updated: 2025/04/16 16:56:20 by khais ### ########.fr */ /* Updated: 2025/04/25 17:58:15 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,17 +19,19 @@
static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app, static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
bool should_exit) bool should_exit)
{ {
cmd_execute(cmd->first, app, should_exit); (void)should_exit;
cmd_execute(cmd->first, app, false);
if (app->last_return_value == 0) if (app->last_return_value == 0)
cmd_execute(cmd->second, app, should_exit); cmd_execute(cmd->second, app, false);
} }
static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app, static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
bool should_exit) bool should_exit)
{ {
cmd_execute(cmd->first, app, should_exit); (void)should_exit;
cmd_execute(cmd->first, app, false);
if (app->last_return_value != 0) if (app->last_return_value != 0)
cmd_execute(cmd->second, app, should_exit); cmd_execute(cmd->second, app, false);
} }
void connec_cmd_execute(t_connec_cmd *cmd, t_minishell *app, void connec_cmd_execute(t_connec_cmd *cmd, t_minishell *app,

48
test.sh
View file

@ -1284,4 +1284,52 @@ hello
hi hi
EOF EOF
when_run <<EOF "and withing subshell"
touch hi hello
(ls && ls)
echo \$?
EOF
expecting <<EOF
hello
hi
hello
hi
0
EOF
when_run <<EOF "or withing subshell"
touch hi hello
(false || ls)
echo \$?
EOF
expecting <<EOF
hello
hi
0
EOF
when_run <<EOF "and"
touch hi hello
ls && ls
echo \$?
EOF
expecting <<EOF
hello
hi
hello
hi
0
EOF
when_run <<EOF "or"
touch hi hello
false || ls
echo \$?
EOF
expecting <<EOF
hello
hi
0
EOF
finalize finalize