cd: print error if cd is called with too many arguments

This commit is contained in:
Khaïs COLIN 2025-03-31 20:06:13 +02:00
parent a66b71e5ce
commit 7153df9305
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 21 additions and 1 deletions

View file

@ -6,11 +6,12 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
#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);

13
test.sh
View file

@ -259,6 +259,19 @@ expecting <<EOF
/tmp/dir.minishell/test/hello/world
EOF
when_run <<EOF "cd print error when given too many arguments"
cd hello there
pwd
cd . ..
pwd
EOF
expecting <<EOF
minishell: cd: too many arguments
/tmp/dir.minishell
minishell: cd: too many arguments
/tmp/dir.minishell
EOF
when_run <<EOF "quoted parentheses are not operators"
echo unclosed '('
EOF