gysiang / minishell

0 stars 1 forks source link

$PATH issue #254

Closed gysiang closed 4 months ago

gysiang commented 4 months ago

@axellee1994 This part has issue, getenv gets from bash and not our minishell. replace it with the custom that gets from the env manager.

char get_path(char cmd, t_shell minishell) { int i; char exec; char *path_part; char all_path; char s_cmd;

(void)minishell;
i = -1;
**all_path = ft_split(getenv("PATH"), ':');**
s_cmd = ft_split(cmd, ' ');
while (all_path[++i])
{
    path_part = ft_strjoin(all_path[i], "/");
    exec = ft_strjoin(path_part, s_cmd[0]);
    free(path_part);
    if (access(exec, F_OK | X_OK) == 0)
    {
        ft_free_two_tabs(s_cmd, all_path);
        return (exec);
    }
    free(exec);
}
ft_free_two_tabs(all_path, s_cmd);
return (NULL);

}

axellee1994 commented 4 months ago

Okay can do.

gysiang commented 4 months ago

To test, remove the path and run a command like ls, cat, grep.

axellee1994 commented 4 months ago

@gysiang try to replace getenv to get_env_value.

That will make it use our custom

axellee1994 commented 4 months ago

That time we had a lot of memory errors, so I used the allowed function getenv to substitute it.

axellee1994 commented 4 months ago

image @gysiang Resolved. Pushing after clean up

To test:

  1. Start your minishell
  2. Set a custom environment variable: export TEST_VAR=minishell_value
  3. Run the test command: test_env
  4. It should output: TEST_VAR=minishell_value
  5. Exit your minishell
  6. In bash, run: echo $TEST_VAR
  7. It should be empty or different from "minishell_value" This will confirm that get_env_value is indeed getting the environment from your minishell and not from the parent bash process.