From 7153df93050f01b6b708c59d6585ae97e89dd877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Mon, 31 Mar 2025 20:06:13 +0200 Subject: [PATCH] cd: print error if cd is called with too many arguments --- src/executing/simple_cmd/builtin_cd.c | 9 ++++++++- test.sh | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/executing/simple_cmd/builtin_cd.c b/src/executing/simple_cmd/builtin_cd.c index 98749f1..eb90fa3 100644 --- a/src/executing/simple_cmd/builtin_cd.c +++ b/src/executing/simple_cmd/builtin_cd.c @@ -6,11 +6,12 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/31 16:20:17 by khais #+# #+# */ -/* Updated: 2025/03/31 17:05:21 by khais ### ########.fr */ +/* Updated: 2025/03/31 20:04:28 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "builtins.h" +#include "ft_printf.h" #include "libft.h" #include #include "../../env/env_manip.h" @@ -48,6 +49,12 @@ t_builtin_type builtin_cd(t_simple_cmd *cmd, t_minishell *app) { t_worddesc *arg; + if (wordlist_get(cmd->words, 2) != NULL) + { + ft_dprintf(STDERR_FILENO, "minishell: cd: too many arguments\n"); + app->last_return_value = 1; + return (BUILTIN_CD); + } arg = wordlist_get(cmd->words, 1); if (arg == NULL) chdir_home(app); diff --git a/test.sh b/test.sh index 3b44eab..1c7f237 100755 --- a/test.sh +++ b/test.sh @@ -259,6 +259,19 @@ expecting <