Skip to content

Commit 3e1fb2a

Browse files
committed
[~] Fix issues with default path (now it's exactly the same as tcsh)
1 parent 515ad68 commit 3e1fb2a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/command.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ builtin_t *get_builtin_command(int index)
4242
static char *get_command_path(char *command, char **env)
4343
{
4444
char *path = NULL;
45-
char **path_tab = my_str_to_word_array_select(
46-
get_env_var(env, "PATH"), ":");
45+
char *var = (get_env_var(env, "PATH") ?
46+
get_env_var(env, "PATH") : get_variable_value(get_mysh(), "path"));
47+
char **path_tab = my_str_to_word_array_select(var, ": ");
4748

4849
for (int index = 0; path_tab[index] != NULL; index++) {
4950
path = my_malloc(sizeof(char) * (my_strlen(path_tab[index]) +

src/environnement.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ void replace_env_var(char **env, char *name, char *value)
6767
*/
6868
void check_path(mysh_t *mysh)
6969
{
70-
if (get_env_var(mysh->env, "PATH") == NULL)
71-
set_new_env_var(mysh, "PATH", "/usr/bin:/bin");
70+
char *path = get_env_var(mysh->env, "PATH");
71+
72+
if (path == NULL)
73+
add_variable(mysh, "path", "/usr/bin /bin");
74+
else {
75+
my_replace_char(path, ':', ' ');
76+
add_variable(mysh, "path", path);
77+
}
7278
}
7379

7480
/**

0 commit comments

Comments
 (0)