fix: "echo $" works

This commit is contained in:
Camille Chauvet
2023-03-22 14:59:19 +01:00
parent 72ff3ba134
commit b3d060874d
8 changed files with 19 additions and 14 deletions

9
env/env_fill.c vendored
View File

@ -22,6 +22,8 @@ static char *ft_getkey(const char *str)
key = ft_strdup("$");
else if (ft_strncmp(str, "$?", 2) == 0)
key = ft_strdup("?");
if (str[1] == '\0')
key = ft_strdup("");
else
{
i = 1;
@ -42,12 +44,14 @@ static char *ft_getvalue(t_data *data, char *key)
value = ft_itoa(data->exit_code);
else if (ft_strcmp(key, "$") == 0)
value = ft_strdup("PID");
else if (key[0] == '\0')
value = ft_strdup("$");
else
{
value = get_value_by_key(key, data->env);
if (value == NULL)
value = ft_strdup("");
else
else
value = ft_strdup(value);
}
if (value == NULL)
@ -55,7 +59,8 @@ static char *ft_getvalue(t_data *data, char *key)
return (value);
}
static char *ft_getvalue_by_str(t_data *data, const char *str, size_t *key_len)
static char *ft_getvalue_by_str(t_data *data, const char *str,
size_t *key_len)
{
char *key;
char *value;