-
Notifications
You must be signed in to change notification settings - Fork 1
/
echo.c
52 lines (47 loc) · 1.36 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: simao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/12 16:40:25 by simao #+# #+# */
/* Updated: 2023/08/07 19:47:59 by simao ### ########.fr */
/* */
/* ************************************************************************** */
#include "../minishell.h"
int check_option(char *opt)
{
int i;
if (ft_strncmp(opt, "-n", 2))
return (1);
i = 1;
while (opt[i])
{
if (opt[i] != 'n')
return (1);
i++;
}
return (2);
}
void cmd_echo(char **line)
{
int i;
i = 0;
if (!line[1])
return ;
i = check_option(line[1]);
if (line[i] == NULL)
ft_printf("");
else
{
while (line[i + 1])
{
ft_printf("%s ", line[i]);
i++;
}
ft_printf("%s", line[i]);
if (check_option(line[1]) == 1)
ft_printf("\n");
}
}