From d66ca10a0c100db9173c58d4af5f6a3780ec3b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Mon, 31 Mar 2025 16:40:01 +0200 Subject: [PATCH] cd: with no arg, go to $HOME --- src/executing/simple_cmd/builtin_cd.c | 9 +++++---- test.sh | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/executing/simple_cmd/builtin_cd.c b/src/executing/simple_cmd/builtin_cd.c index 7bb2c1d..123dfdb 100644 --- a/src/executing/simple_cmd/builtin_cd.c +++ b/src/executing/simple_cmd/builtin_cd.c @@ -6,13 +6,13 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/31 16:20:17 by khais #+# #+# */ -/* Updated: 2025/03/31 16:32:52 by khais ### ########.fr */ +/* Updated: 2025/03/31 16:39:30 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "builtins.h" #include -#include "libft.h" +#include "../../env/env_manip.h" #include "../../ft_errno.h" static void ft_chdir(char *path, t_minishell *app) @@ -30,12 +30,13 @@ static void ft_chdir(char *path, t_minishell *app) t_builtin_type builtin_cd(t_simple_cmd *cmd, t_minishell *app) { t_worddesc *arg; + char *home; arg = wordlist_get(cmd->words, 1); if (arg == NULL) { - app->last_return_value = 1; - ft_dprintf(STDERR_FILENO, "TODO: cd to $HOME\n"); + home = env_get_val(app->env, "HOME"); + ft_chdir(home, app); } else ft_chdir(arg->word, app); diff --git a/test.sh b/test.sh index d9c7cc7..d22903a 100755 --- a/test.sh +++ b/test.sh @@ -188,6 +188,15 @@ minishell: cd: Permission denied /tmp/dir.minishell EOF +HOME=/tmp/dir.minishell/fakehome when_run <