From b6d847ae20c32744d508eced2be3132c3fa8c5b9 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sat, 19 Oct 2013 13:51:04 +0000 Subject: [PATCH] implementation of echo --- utils/echo/Makefile | 7 +++++++ utils/echo/echo.c | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 utils/echo/Makefile create mode 100644 utils/echo/echo.c diff --git a/utils/echo/Makefile b/utils/echo/Makefile new file mode 100644 index 0000000..f1f3a63 --- /dev/null +++ b/utils/echo/Makefile @@ -0,0 +1,7 @@ +CFLAGS=-Wall + +echo: echo.c + $(CC) $(CFLAGS) -o $@ $+ + +echo.html: + wget http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html diff --git a/utils/echo/echo.c b/utils/echo/echo.c new file mode 100644 index 0000000..1c22080 --- /dev/null +++ b/utils/echo/echo.c @@ -0,0 +1,22 @@ +#include +#include +#include + +int main(int ac, char *av[]) { + int nl = 1; + int as = 1; + int i; + + if (ac && !strcmp(av[1], "-n")) { + as++; + nl=0; + } + + for (i=as; i < ac; i++) { + printf("%s%s", i > as ? " " : "", av[i]); + } + + if (nl) printf("\n"); + + exit(0); +} -- 2.40.0