fix: "echo $" works
This commit is contained in:
parent
72ff3ba134
commit
b3d060874d
BIN
.nfs00000000098c816100000162
Executable file
BIN
.nfs00000000098c816100000162
Executable file
Binary file not shown.
@ -4,5 +4,7 @@
|
|||||||
# include "../libftx/libftx.h"
|
# include "../libftx/libftx.h"
|
||||||
# include "../env/env.h"
|
# include "../env/env.h"
|
||||||
# include "../utils/utils.h"
|
# include "../utils/utils.h"
|
||||||
|
|
||||||
char *get_pwd(int fd);
|
char *get_pwd(int fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,5 +10,6 @@ typedef struct s_data
|
|||||||
int child_pid;
|
int child_pid;
|
||||||
} t_data;
|
} t_data;
|
||||||
|
|
||||||
t_data *ft_get_data();
|
t_data *ft_get_data(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
7
env/env_fill.c
vendored
7
env/env_fill.c
vendored
@ -22,6 +22,8 @@ static char *ft_getkey(const char *str)
|
|||||||
key = ft_strdup("$");
|
key = ft_strdup("$");
|
||||||
else if (ft_strncmp(str, "$?", 2) == 0)
|
else if (ft_strncmp(str, "$?", 2) == 0)
|
||||||
key = ft_strdup("?");
|
key = ft_strdup("?");
|
||||||
|
if (str[1] == '\0')
|
||||||
|
key = ft_strdup("");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = 1;
|
i = 1;
|
||||||
@ -42,6 +44,8 @@ static char *ft_getvalue(t_data *data, char *key)
|
|||||||
value = ft_itoa(data->exit_code);
|
value = ft_itoa(data->exit_code);
|
||||||
else if (ft_strcmp(key, "$") == 0)
|
else if (ft_strcmp(key, "$") == 0)
|
||||||
value = ft_strdup("PID");
|
value = ft_strdup("PID");
|
||||||
|
else if (key[0] == '\0')
|
||||||
|
value = ft_strdup("$");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value = get_value_by_key(key, data->env);
|
value = get_value_by_key(key, data->env);
|
||||||
@ -55,7 +59,8 @@ static char *ft_getvalue(t_data *data, char *key)
|
|||||||
return (value);
|
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 *key;
|
||||||
char *value;
|
char *value;
|
||||||
|
@ -115,10 +115,8 @@ int ft_cmds_parser(t_data *data, const char *line)
|
|||||||
}
|
}
|
||||||
if (*data->cmds != NULL)
|
if (*data->cmds != NULL)
|
||||||
{
|
{
|
||||||
if (((t_cmd *) (*data->cmds)->content)->fd_in[0] == -1)
|
ft_add_fd(((t_cmd *)(*data->cmds)->content)->fd_in, 0);
|
||||||
((t_cmd *) (*data->cmds)->content)->fd_in[0] = 0;
|
ft_add_fd(((t_cmd *)(ft_lstlast(*data->cmds))->content)->fd_out, 1);
|
||||||
if (((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] == -1)
|
|
||||||
(((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] = 1);
|
|
||||||
}
|
}
|
||||||
ft_freer_tab_ultimate(1, tab);
|
ft_freer_tab_ultimate(1, tab);
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
# include "../cmd/cmd.h"
|
# include "../cmd/cmd.h"
|
||||||
|
|
||||||
int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str);
|
int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str);
|
||||||
int *ft_get_heredoc();
|
int *ft_get_heredoc(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,10 +54,10 @@ char *ft_get_executable_without_path(t_data *data, const char *name)
|
|||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
break;
|
break ;
|
||||||
}
|
}
|
||||||
if (access(path, X_OK) == 0)
|
if (access(path, X_OK) == 0)
|
||||||
break;
|
break ;
|
||||||
free(path);
|
free(path);
|
||||||
path = NULL;
|
path = NULL;
|
||||||
i++;
|
i++;
|
||||||
|
@ -32,5 +32,4 @@ char *ft_get_executable(t_data *data, const char *name);
|
|||||||
void ft_closer(int fds[2]);
|
void ft_closer(int fds[2]);
|
||||||
void ft_add_fd(int fds[2], int fd);
|
void ft_add_fd(int fds[2], int fd);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user