gysiang / minishell

0 stars 1 forks source link

Echo Issues #78

Closed axellee1994 closed 4 months ago

axellee1994 commented 5 months ago
axellee1994 commented 5 months ago

Need to enter into EDIT to see all of the full testcases. \ is being hidden atm

axellee1994 commented 4 months ago

@gysiang If you are free, can please try to solve some of these test cases?

I need to refactor a few more codes like builtin_export, unset etc.

axellee1994 commented 4 months ago

image

Went into redirection instead of just printing out as string literal

gysiang commented 4 months ago

minishell$ echo "$PWD" in parse double quotes token: echo token type: 0 token: /home/gyong-si/Documents/42/minishell token type: 0 /home/gyong-si/Documents/42/minishell minishell$

Its working in the new pull request, the flag i put in was refactored into a wrong place. I'll work on cleaning up my code and checking through the eval requirements. Can you finish the rest of the echo test cases?

axellee1994 commented 4 months ago

minishell$ echo "$PWD"

in parse double quotes

token: echo

token type: 0

token: /home/gyong-si/Documents/42/minishell

token type: 0

/home/gyong-si/Documents/42/minishell

minishell$

Its working in the new pull request, the flag i put in was refactored into a wrong place. I'll work on cleaning up my code and checking through the eval requirements. Can you finish the rest of the echo test cases?

Yeah I am still working on it, like the echo$TEST$TEST etc.

gysiang commented 4 months ago

echo "$TEST" Output: "\TEST" Correct Output: $TEST

Is this test case correct? @axellee1994 I stop working on these echo two people changing the code makes it harder to work on it.

axellee1994 commented 4 months ago

I already screenshot the what the correct output needed to be.

GitHub won't let me display that backslash.

axellee1994 commented 4 months ago

@gysiang , can you help me to double check how does echo $PWD etc. is able to get their environment value?

The reason is because in the handle_env_variable, if the environment variable does not exists, it will display an empty string. So commands like echo "$TEST$TEST=lol" will result in =lol.

But when echo $TEST, it will still display as $TEST

axellee1994 commented 4 months ago

@gysiang found the issue for echo $?HELLO.

It is the custom realloc issue that was corrupting it. image

gysiang commented 4 months ago

@gysiang , can you help me to double check how does echo $PWD etc. is able to get their environment value?

The reason is because in the handle_env_variable, if the environment variable does not exists, it will display an empty string. So commands like echo "$TEST$TEST=lol" will result in =lol.

But when echo $TEST, it will still display as $TEST

I think this is because of another test case. I tweaked the parser for it to add back the $ into the token. Now when i try this in bash, it should return just a space or null when it cannot find the variable in env.

echo "$TEST" Output: "\TEST" Correct Output: $TEST

void    handle_variable_not_found(char **result, t_shell *minishell, const char *var_name)
{
    char    *temp;

    temp = prepend_dollar(var_name);
    append_to_result(result, minishell, temp);
    free(temp);
}
axellee1994 commented 4 months ago

@gysiang , can you help me to double check how does echo $PWD etc. is able to get their environment value? The reason is because in the handle_env_variable, if the environment variable does not exists, it will display an empty string. So commands like echo "$TEST$TEST=lol" will result in =lol. But when echo $TEST, it will still display as $TEST

I think this is because of another test case. I tweaked the parser for it to add back the $ into the token. Now when i try this in bash, it should return just a space or null when it cannot find the variable in env.

echo "$TEST" Output: "\TEST" Correct Output: $TEST

void  handle_variable_not_found(char **result, t_shell *minishell, const char *var_name)
{
  char    *temp;

  temp = prepend_dollar(var_name);
  append_to_result(result, minishell, temp);
  free(temp);
}

Okay can thanks, I will check this on my side now.

axellee1994 commented 4 months ago

@gysiang , can you help me to double check how does echo $PWD etc. is able to get their environment value? The reason is because in the handle_env_variable, if the environment variable does not exists, it will display an empty string. So commands like echo "$TEST$TEST=lol" will result in =lol. But when echo $TEST, it will still display as $TEST

I think this is because of another test case. I tweaked the parser for it to add back the $ into the token. Now when i try this in bash, it should return just a space or null when it cannot find the variable in env.

echo "$TEST" Output: "\TEST" Correct Output: $TEST

void  handle_variable_not_found(char **result, t_shell *minishell, const char *var_name)
{
  char    *temp;

  temp = prepend_dollar(var_name);
  append_to_result(result, minishell, temp);
  free(temp);
}

For this particular testcase, because there is a backslash, it is supposed to treat everything behind it as a string literal, meaning that echo "'backslash$TEST" is supposed to be treated as echo '$TEST'.

axellee1994 commented 4 months ago

@gysiang Ivan, please today take a break . I am checking on my side for the codes and resolving the issues. Thanks 🙏