From ad628ed4f2f03fe3df8b5a0f2682b738d34d13ed Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 23 Aug 2020 20:20:11 +0200 Subject: Added yes (yes) --- README.md | 1 + src/yes.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/yes.c diff --git a/README.md b/README.md index 11ca0f7..b287118 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Rewrite of some core utilities for educational purposes. | `tee` | read from standard input and write to standard output and files | | `shuf` | generate random permutations | | `echo` | display a line of text | +| `yes` | output a string repeatedly until killed | ## Pending diff --git a/src/yes.c b/src/yes.c new file mode 100644 index 0000000..9ae510c --- /dev/null +++ b/src/yes.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int main(int argc, char **argv) +{ + while (true) + { + if (argc == 1) + fputs("y", stdout); + else + for (int i = 1; i < argc; i++) + { + fputs(argv[i], stdout); + if (i < argc - 1) + putchar(' '); + } + putchar('\n'); + } + return EXIT_SUCCESS; +} -- cgit