summaryrefslogtreecommitdiff
path: root/src/commands/yes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/yes.c')
-rw-r--r--src/commands/yes.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/commands/yes.c b/src/commands/yes.c
new file mode 100644
index 0000000..c954810
--- /dev/null
+++ b/src/commands/yes.c
@@ -0,0 +1,26 @@
+#include "../command.h"
+
+static void help() {
+ printf("Usage: yes [STRING]\n\n");
+ printf("Repeatedly output a line with all specified STRING(s), or 'y'.\n");
+ exit(EXIT_SUCCESS);
+}
+
+COMMAND(yes) {
+ const char* repeat;
+ if (argc == 0) {
+ repeat = "y";
+ } else {
+ if (streql("--help", argv[0])) {
+ help();
+ }
+ repeat = argv[0];
+ for (int i = 1; i < argc; i++) {
+ *(argv[i]-1) = ' ';
+ }
+ }
+
+ while (true) {
+ printf("%s\n", repeat);
+ }
+}