-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.c
More file actions
58 lines (49 loc) · 741 Bytes
/
variable.c
File metadata and controls
58 lines (49 loc) · 741 Bytes
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
50
51
52
53
54
55
56
57
#include "shell.h"
/**
* rmvar - removes $ sign from string
* @str: string
*
* Return: altered string.
*/
char *rmvar(char *str)
{
int i = 1, j = 0, len;
char *new;
if (str == NULL)
return (NULL);
len = _strlen(str);
new = malloc(sizeof(char) * len);
if (new == NULL)
return (NULL);
while (str[i])
{
new[j] = str[i];
j++;
i++;
}
new[j] = '\0';
free(str);
return (new);
}
/**
* variable - handles variables in
* the environmner
* @shellf: shell info
*/
void variable(shell_info shellf)
{
int i = 0;
char *str;
if (!(shellf.args))
return;
while (shellf.args[i])
{
if (shellf.args[i][0] == '$')
{
str = rmvar(shellf.args[i]);
shellf.args[i] = _getenv(str);
free(str);
}
i++;
}
}