@@ -45,7 +45,7 @@ int cmd_help(struct tokens *tokens);
45
45
int cmd_pwd (struct tokens * tokens );
46
46
int cmd_cd (struct tokens * tokens );
47
47
char * procpathenv (char * , char * );
48
-
48
+ char * detpath ( char * );
49
49
const int MAX_PATH_SIZE = 128 ;
50
50
51
51
/* Built-in command functions take token array (see parse.h) and return int */
@@ -99,8 +99,9 @@ int cmd_cd(struct tokens *tokens){
99
99
}
100
100
101
101
/* Execute program */
102
- int shell_exec (struct tokens * tokens ){
103
- char * path = tokens_get_token (tokens , 0 );
102
+ int shell_exec (struct tokens * tokens ){
103
+ /* path processed by detpath and then we could use it */
104
+ char * path = detpath (tokens_get_token (tokens , 0 ));
104
105
char * * args = (char * * )malloc (tokens -> tokens_length * sizeof (char * ));
105
106
for (int i = 0 ; i < tokens -> tokens_length ; i ++ ){
106
107
args [i ] = tokens_get_token (tokens , i );
@@ -124,7 +125,6 @@ int shell_exec(struct tokens *tokens){
124
125
125
126
/*
126
127
Shell can use both absolute path and relative path.
127
- TODO: shell should use PATH variables to lookup programs
128
128
1. Determine whether is there the symbol '/'.
129
129
2. If it does then path is absolute, so we just use it.
130
130
3. If it doesn't then either it is a relative path and we use it or it is name of the program.
0 commit comments