Skip to content

Commit

Permalink
fixed command not found on empty quotes and echo $ between double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste Renaudon authored and Baptiste Renaudon committed Jan 13, 2023
1 parent cadaa19 commit d44eca2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
1 change: 0 additions & 1 deletion builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ int builtin(char *cmd)
}
i++;
}
printf("jsp: %s\n", cmd_split[0]);
free_tab(cmd_split);
return (-1);
}
Expand Down
3 changes: 2 additions & 1 deletion dollar.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ void find_var(t_token *token, char *input)
i++;
len++;
}
if (len == 0 && (input[i] == '\'' || input[i] == '\"'))
if (len == 0 && (input[i] == '\'' || input[i] == '\"') \
&& i > 1 && input[i - 2] != '\"')
token->arg = ft_strdup("-");
else
token->arg = ft_substr(input, token->str_idx + 1, len);
Expand Down
1 change: 0 additions & 1 deletion minishell.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void events(t_list **head)
{
scan_heredocs();
get_cmd();
print_cmds();
if (!g_glob->sig_int)
pipex();
unlink_heredocs();
Expand Down
5 changes: 1 addition & 4 deletions pipex_children.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ void child(t_cmd *cmd, int *pipes, int *children_pid)
char **envp;
char **cmd_split;

ft_printf("0- cmd: %s\n", cmd->str);
if (cmd->fd_in != -1 && cmd->fd_out != -1 \
&& cmd->str && cmd->str[0] != '\0')
{
g_glob->exit_ret = 1;
cmd_split = ft_split_quotes(cmd->str, " \t");
cmd_split[0] = remove_quotes(cmd_split[0]);
ft_printf("1- cmd: %s\n", cmd_split[0]);
cmd_split[0] = get_path(cmd_split[0], false);
ft_printf("2- cmd: %s\n", cmd_split[0]);
exit_on_error(cmd, cmd_split, pipes, children_pid);
dup_and_close(cmd, pipes);
envp = envp_list_to_tab();
Expand Down Expand Up @@ -80,7 +77,7 @@ static char *get_path_loop(char *cmd, t_list *envp_entry)
{
cmd_absolute = ft_strjoin(paths[i], "/");
cmd_absolute = ft_strjoinf(cmd_absolute, cmd);
if (access(cmd_absolute, 0) == 0)
if (access(cmd_absolute, 0) == 0 && !is_dir(cmd_absolute))
{
free_tab(paths);
free(cmd);
Expand Down
11 changes: 10 additions & 1 deletion utils_pipex.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ void exit_on_permission(char **cmd_split, \

void print_cmd_not_found(char *str)
{
ft_putstr_fd(str, 2);
char **str_split;

str_split = ft_split_quotes(str, " \t");
if (str_split[0][0] == '\0')
{
free(str_split[0]);
str_split[0] = ft_strdup("\'\'");
}
ft_putstr_fd(str_split[0], 2);
ft_putstr_fd(": command not found\n", 2);
free_tab(str_split);
}

void close_pipes(int *pipes)
Expand Down

0 comments on commit d44eca2

Please sign in to comment.