export: set correct exit status

This commit is contained in:
Khaïs COLIN 2025-04-01 15:58:34 +02:00
parent 3cdf7c3f76
commit ba4192bf8d
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 9 additions and 1 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/01 14:00:32 by khais #+# #+# */ /* Created: 2025/04/01 14:00:32 by khais #+# #+# */
/* Updated: 2025/04/01 15:53:06 by khais ### ########.fr */ /* Updated: 2025/04/01 15:58:28 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,6 +32,7 @@ static void single_export(char *arg, t_minishell *app)
ft_dprintf(STDERR_FILENO, ft_dprintf(STDERR_FILENO,
"minishell: export: `%s': not a valid identifier\n", arg); "minishell: export: `%s': not a valid identifier\n", arg);
free2(key, value); free2(key, value);
app->last_return_value = 1;
} }
else if (env_set_entry(&app->env, key, value) == NULL) else if (env_set_entry(&app->env, key, value) == NULL)
ft_perror("minishell: export"); ft_perror("minishell: export");
@ -45,6 +46,7 @@ t_builtin_type builtin_export(t_simple_cmd *cmd, t_minishell *app)
i = 1; i = 1;
arg = wordlist_get(cmd->words, i++); arg = wordlist_get(cmd->words, i++);
app->last_return_value = 0;
while (arg != NULL) while (arg != NULL)
{ {
single_export(arg->word, app); single_export(arg->word, app);

View file

@ -307,25 +307,31 @@ EXTRAENV=-i
when_run <<EOF "export with strange inputs" when_run <<EOF "export with strange inputs"
export PATH=$PATH export PATH=$PATH
export var export var
echo status=\$?
echo var=[\$var] echo var=[\$var]
export blue= export blue=
echo status=\$?
echo blue=[\$blue] echo blue=[\$blue]
env -u PATH env env -u PATH env
EOF EOF
expecting <<EOF expecting <<EOF
status=0
var=[] var=[]
status=0
blue=[] blue=[]
blue= blue=
EOF EOF
when_run <<"EOF" "export with invalid identifiers" when_run <<"EOF" "export with invalid identifiers"
export = 123=456 hello=hi 456=789 export = 123=456 hello=hi 456=789
echo status=$?
echo hello=$hello echo hello=$hello
EOF EOF
expecting <<"EOF" expecting <<"EOF"
minishell: export: `=': not a valid identifier minishell: export: `=': not a valid identifier
minishell: export: `123=456': not a valid identifier minishell: export: `123=456': not a valid identifier
minishell: export: `456=789': not a valid identifier minishell: export: `456=789': not a valid identifier
status=1
hello=hi hello=hi
EOF EOF