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

BIN
.nfs00000000098c816100000162 Executable file

Binary file not shown.

View File

@ -4,5 +4,7 @@
# include "../libftx/libftx.h"
# include "../env/env.h"
# include "../utils/utils.h"
char *get_pwd(int fd);
#endif

View File

@ -10,5 +10,6 @@ typedef struct s_data
int child_pid;
} t_data;
t_data *ft_get_data();
t_data *ft_get_data(void);
#endif

7
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,6 +44,8 @@ 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);
@ -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;

View File

@ -115,10 +115,8 @@ int ft_cmds_parser(t_data *data, const char *line)
}
if (*data->cmds != NULL)
{
if (((t_cmd *) (*data->cmds)->content)->fd_in[0] == -1)
((t_cmd *) (*data->cmds)->content)->fd_in[0] = 0;
if (((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] == -1)
(((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] = 1);
ft_add_fd(((t_cmd *)(*data->cmds)->content)->fd_in, 0);
ft_add_fd(((t_cmd *)(ft_lstlast(*data->cmds))->content)->fd_out, 1);
}
ft_freer_tab_ultimate(1, tab);
return (0);

View File

@ -4,6 +4,6 @@
# include "../cmd/cmd.h"
int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str);
int *ft_get_heredoc();
int *ft_get_heredoc(void);
#endif

View File

@ -54,10 +54,10 @@ char *ft_get_executable_without_path(t_data *data, const char *name)
if (path == NULL)
{
ft_eprintf("minishell: malloc failed\n");
break;
break ;
}
if (access(path, X_OK) == 0)
break;
break ;
free(path);
path = NULL;
i++;

View File

@ -32,5 +32,4 @@ char *ft_get_executable(t_data *data, const char *name);
void ft_closer(int fds[2]);
void ft_add_fd(int fds[2], int fd);
#endif