-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.c
More file actions
45 lines (43 loc) · 917 Bytes
/
Copy pathecho.c
File metadata and controls
45 lines (43 loc) · 917 Bytes
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
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/utsname.h>
void parseInput(char *input)
{
input += 4; // Skip the "echo" part
while (*input == ' ' || *input == '\t')
input++;
bool inQuotes = false;
while (*input != '\0')
{
if (*input == '\"')
{
inQuotes = !inQuotes;
}
else if (*input == ' ' || *input == '\t')
{
if (!inQuotes)
{
printf(" ");
while (*input == ' ' || *input == '\t')
input++;
input--;
}
else
{
printf("%c", *input);
}
}
else
{
printf("%c", *input);
}
input++;
}
printf("\n");
}