mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
unset: implement unset
This commit is contained in:
parent
1ef8b7a0ae
commit
d40560bb37
6 changed files with 43 additions and 4 deletions
28
src/executing/simple_cmd/builtin_unset.c
Normal file
28
src/executing/simple_cmd/builtin_unset.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_unset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/03 14:35:53 by khais #+# #+# */
|
||||
/* Updated: 2025/04/03 14:39:45 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtins.h"
|
||||
#include "../../env/env_manip.h"
|
||||
|
||||
t_builtin_type builtin_unset(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
t_wordlist *arg;
|
||||
|
||||
arg = cmd->words->next;
|
||||
while (arg != NULL)
|
||||
{
|
||||
env_rm_entry(&app->env, arg->word->word);
|
||||
arg = arg->next;
|
||||
}
|
||||
app->last_return_value = 0;
|
||||
return (BUILTIN_UNSET);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/01 16:37:21 by khais #+# #+# */
|
||||
/* Updated: 2025/04/03 14:16:55 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/03 14:35:30 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +30,8 @@ t_builtin_type get_builtin(t_simple_cmd *cmd)
|
|||
return (BUILTIN_ECHO);
|
||||
if (ft_strcmp("env", word) == 0)
|
||||
return (BUILTIN_ENV);
|
||||
if (ft_strcmp("unset", word) == 0)
|
||||
return (BUILTIN_UNSET);
|
||||
return (BUILTIN_INVALID);
|
||||
}
|
||||
|
||||
|
|
@ -44,6 +46,7 @@ t_builtin_type execute_builtin(t_simple_cmd *cmd, t_minishell *app)
|
|||
[BUILTIN_EXIT] = builtin_exit,
|
||||
[BUILTIN_ECHO] = builtin_echo,
|
||||
[BUILTIN_ENV] = builtin_env,
|
||||
[BUILTIN_UNSET] = builtin_unset,
|
||||
};
|
||||
|
||||
type = get_builtin(cmd);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 14:16:13 by khais #+# #+# */
|
||||
/* Updated: 2025/04/03 14:17:17 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/03 14:35:44 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ t_builtin_type builtin_export(t_simple_cmd *cmd, t_minishell *app);
|
|||
t_builtin_type builtin_exit(t_simple_cmd *cmd, t_minishell *app);
|
||||
t_builtin_type builtin_echo(t_simple_cmd *cmd, t_minishell *app);
|
||||
t_builtin_type builtin_env(t_simple_cmd *cmd, t_minishell *app);
|
||||
t_builtin_type builtin_unset(t_simple_cmd *cmd, t_minishell *app);
|
||||
|
||||
t_builtin_type get_builtin(t_simple_cmd *cmd);
|
||||
t_builtin_type execute_builtin(t_simple_cmd *cmd, t_minishell *app);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/03 14:17/26 by khais #+# #+# */
|
||||
/* Updated: 2025/04/03 14:17:26 by khais ### ########.fr */
|
||||
/* Created: 2025/04/03 14:35/14 by khais #+# #+# */
|
||||
/* Updated: 2025/04/03 14:35:14 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,6 +27,7 @@ typedef enum e_builtin_type
|
|||
BUILTIN_EXIT,
|
||||
BUILTIN_ECHO,
|
||||
BUILTIN_ENV,
|
||||
BUILTIN_UNSET,
|
||||
} t_builtin_type;
|
||||
|
||||
#endif // SIMPLE_CMD_EXECUTE_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue