-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshell_echo.c
More file actions
50 lines (48 loc) · 1.11 KB
/
shell_echo.c
File metadata and controls
50 lines (48 loc) · 1.11 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
int echo_quote(char buf[]){
int len,i=0,j,k=0,end,start = 0;
char quote,temp[10000];
len = strlen(buf);
end = len - 1;
while(buf[start]==' ' || buf[start]=='\t'){
start++;
}
start+=4;
while(buf[start]==' ' || buf[start]=='\t'){
start++;
}
// printf("%c",buf[start]);
while(buf[end]==' ' || buf[end]=='\t')
end--;
// printf("%c",buf[end]);
if(buf[start]=='\'' || buf[start]=='\"'){
if(buf[end]!=buf[start]){
printf("echo : string invalid\n");
return 0;
}
else{
quote = buf[start];
for(j=start;j<=end;j++){
if(buf[j]!=quote){
temp[k] = buf[j];
k++;
}
}
temp[k]='\0';
}
printf("%s\n",temp);
}
else
printf("%s\n",&buf[i]);
return 0;
}
int echo(char **tokenlist,int index){
int i;
for(i=1;i<index;i++)
printf("%s ",tokenlist[i]);
printf("\n");
return 0;
}