blob: c60d8f01129dc854ba8c6ae16cce9ac23a4b1d96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:11:34 by charles #+# #+# */
/* Updated: 2020/06/18 13:50:47 by charles ### ########.fr */
/* */
/* ************************************************************************** */
/*
** \file export.c
** \brief `export` builtin
*/
// modify existing
// set with no string without '='
// TODO: multiple exported variable (e.g export A=a B=b C=c)
#include "minishell.h"
int builtin_export(char **argv, t_env env)
{
char *temp;
size_t i;
(void)env;
if (argv[1] == NULL)
return (4);
if(ft_isdigit(argv[1][0]))
return(0);
i = 0;
temp = argv[1];
while(temp[i] != '\0')
{
if(temp[i] == ' ' || ft_isalnum(temp[i]) == 0)
return(2);
if (temp[i] == '=')
{
temp[i] = '\0';
env_export(env, temp, argv[1][i + 1]);
return(0);
}
i++;
}
return (3);
}
|