mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
export: set correct exit status
This commit is contained in:
parent
3cdf7c3f76
commit
ba4192bf8d
2 changed files with 9 additions and 1 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
6
test.sh
6
test.sh
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue