diff --git a/src/executing/simple_cmd/builtin_export.c b/src/executing/simple_cmd/builtin_export.c index 5a31b91..214346c 100644 --- a/src/executing/simple_cmd/builtin_export.c +++ b/src/executing/simple_cmd/builtin_export.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/01 14:00:32 by khais #+# #+# */ -/* Updated: 2025/04/01 14:08:53 by khais ### ########.fr */ +/* Updated: 2025/04/01 15:53:06 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,25 +15,39 @@ #include "../../env/env_manip.h" #include "libft.h" #include "../../ft_errno.h" +#include +#include "../../parser/matchers/identifier.h" + +static void single_export(char *arg, t_minishell *app) +{ + char *key; + char *value; + + if (ft_strchr(arg, '=') != NULL) + { + key = envp_get_key(arg); + value = envp_get_val(arg); + if (is_identifier(key) == false) + { + ft_dprintf(STDERR_FILENO, + "minishell: export: `%s': not a valid identifier\n", arg); + free2(key, value); + } + else if (env_set_entry(&app->env, key, value) == NULL) + ft_perror("minishell: export"); + } +} t_builtin_type builtin_export(t_simple_cmd *cmd, t_minishell *app) { int i; t_worddesc *arg; - char *key; - char *value; i = 1; arg = wordlist_get(cmd->words, i++); while (arg != NULL) { - if (ft_strchr(arg->word, '=') != NULL) - { - key = envp_get_key(arg->word); - value = envp_get_val(arg->word); - if (env_set_entry(&app->env, key, value) == NULL) - ft_perror("minishell: export"); - } + single_export(arg->word, app); arg = wordlist_get(cmd->words, i++); } return (BUILTIN_EXPORT); diff --git a/test.sh b/test.sh index 7daccfa..de273f0 100755 --- a/test.sh +++ b/test.sh @@ -318,13 +318,15 @@ blue=[] blue= EOF -when_run <