fix: "echo $" works
This commit is contained in:
9
env/env_fill.c
vendored
9
env/env_fill.c
vendored
@ -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;
|
||||
|
Reference in New Issue
Block a user