Skip to content

Commit bd1efbc

Browse files
author
hyqooo
committed
Debug
1 parent 566a586 commit bd1efbc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

shell.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int cmd_help(struct tokens *tokens);
4545
int cmd_pwd(struct tokens *tokens);
4646
int cmd_cd(struct tokens *tokens);
4747
char *procpathenv(char *, char *);
48-
48+
char *detpath(char *);
4949
const int MAX_PATH_SIZE = 128;
5050

5151
/* Built-in command functions take token array (see parse.h) and return int */
@@ -99,8 +99,9 @@ int cmd_cd(struct tokens *tokens){
9999
}
100100

101101
/* 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));
104105
char **args = (char **)malloc(tokens->tokens_length * sizeof(char *));
105106
for (int i = 0; i < tokens->tokens_length; i++){
106107
args[i] = tokens_get_token(tokens, i);
@@ -124,7 +125,6 @@ int shell_exec(struct tokens *tokens){
124125

125126
/*
126127
Shell can use both absolute path and relative path.
127-
TODO: shell should use PATH variables to lookup programs
128128
1. Determine whether is there the symbol '/'.
129129
2. If it does then path is absolute, so we just use it.
130130
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

Comments
 (0)