-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_echo.c
35 lines (35 loc) · 1.08 KB
/
execute_echo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include"header.h"
#include"variables.h"
int execute_echo(char **args,int flag){
// Usage: echo [option(s)] [string(s)]
int i = 1;
char x = '$';
while(args[i] != NULL){
if(args[i][0] == x){
char s[2000];
strcpy(s, &args[i][1]);
char *print = getenv(s);
if(print)
printf("%s ", print);
}
else{
if(args[i][0] == '\"' || args[i][0] == '\''){
for(int z = 1;z < strlen(args[i]); z++)
if(args[i][z] != '\'' && args[i][z] != '\"')
printf("%c", args[i][z]);
printf(" ");
}
else if (args[i][strlen(args[i])-1] == '\"' || args[i][strlen(args[i])-1] == '\'' ){
for(int z = 0;z < strlen(args[i])-1; z++)
if(args[i][z] != '\'' && args[i][z] != '\"')
printf("%c", args[i][z]);
printf(" ");
}
else
printf("%s ", args[i]);
}
i++;
}
printf("\n");
return 1;
}