aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--src/yes.c21
2 files changed, 22 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+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;
+}