Ajout affichage des variables

This commit is contained in:
rick 2021-02-24 02:01:44 +01:00
parent feb019d000
commit af2081caaf
Signed by: Rick
GPG key ID: 2B593F087240EE99
2 changed files with 25 additions and 3 deletions

View file

@ -19,10 +19,31 @@ void echo(char *args)
char tmp = *args; char tmp = *args;
int i = 0; int i = 0;
while (tmp != '\0') while (tmp != '\0')
{
if (tmp == '$')
{
i++;
i += get_var((args+i), i);
}
else
{ {
putchar(tmp); putchar(tmp);
i++; i++;
}
tmp = *(args + i); tmp = *(args + i);
} }
putchar('\n'); putchar('\n');
} }
int get_var(char *str, int i)
{
char *tmp = calloc(strlen(str), sizeof(char));
strcpy(tmp, str);
char f = ' ';
char *token = strtok(tmp, &f);
printf("%s", getenv(token));
int ret = strlen(token);
free(tmp);
return ret;
}

View file

@ -9,5 +9,6 @@
void usage(); void usage();
void echo(char *args); void echo(char *args);
int get_var(char *str, int i);
#endif #endif