mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
cd: print error if cd is called with too many arguments
This commit is contained in:
parent
a66b71e5ce
commit
7153df9305
2 changed files with 21 additions and 1 deletions
|
|
@ -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
13
test.sh
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue