fixed echo and some return code issues from redirections

This commit is contained in:
mdev9
2024-03-04 13:04:33 +01:00
parent 6d02d62f94
commit e3d93a1262
2 changed files with 10 additions and 9 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
/* Updated: 2024/03/04 11:17:02 by marde-vr ### ########.fr */
/* Updated: 2024/03/04 13:02:28 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,8 +16,10 @@
int echo(t_cmd *args)
{
int put_nl;
int first;
put_nl = 1;
first = 1;
while (args && args->token && !strcmp(args->token, "-n"))
{
put_nl = 0;
@ -29,16 +31,14 @@ int echo(t_cmd *args)
args = args->next;
else
{
ft_putstr_fd(args->token, STDOUT_FILENO);
if (args->next)
{
ft_printf_fd(2, "yes\n");
if (!first)
ft_putchar_fd(' ', STDOUT_FILENO);
}
ft_putstr_fd(args->token, STDOUT_FILENO);
first = 0;
}
args = args->next;
}
if (put_nl)
if (put_nl && !first)
ft_putchar_fd('\n', STDOUT_FILENO);
return (0);
}