blob: 161db82c06018ad7ba4463d2f4c0d3e838cb50b6 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Erik Andersen31638212000-01-15 22:28:50 +00002/*
Manuel Novoa III cad53642003-03-19 09:13:01 +00003 * yes implementation for busybox
Erik Andersen31638212000-01-15 22:28:50 +00004 *
Manuel Novoa III cad53642003-03-19 09:13:01 +00005 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
Erik Andersen31638212000-01-15 22:28:50 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Erik Andersen31638212000-01-15 22:28:50 +00008 */
Manuel Novoa III cad53642003-03-19 09:13:01 +00009/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
10 *
11 * Size reductions and removed redundant applet name prefix from error messages.
12 */
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010013//config:config YES
Denys Vlasenkob097a842018-12-28 03:20:17 +010014//config: bool "yes (1.2 kb)"
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010015//config: default y
16//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020017//config: yes is used to repeatedly output a specific string, or
Denys Vlasenko18e781d2017-08-02 14:12:48 +020018//config: the default string 'y'.
Eric Andersen8d4c3972001-03-09 21:28:09 +000019
Denys Vlasenko7c40ddd2017-08-02 16:37:39 +020020//applet:IF_YES(APPLET_NOEXEC(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
21/* was NOFORK, but then yes can't be ^C'ed if run by hush */
Erik Andersen31638212000-01-15 22:28:50 +000022
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010023//kbuild:lib-$(CONFIG_YES) += yes.o
24
25/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
Denis Vlasenko99912ca2007-04-10 15:43:37 +000026
Denys Vlasenkof2177ab2010-06-06 05:23:09 +020027//usage:#define yes_trivial_usage
28//usage: "[STRING]"
29//usage:#define yes_full_usage "\n\n"
Denys Vlasenko18492852021-06-13 03:12:09 +020030//usage: "Repeatedly print a line with STRING, or 'y'"
Denys Vlasenkof2177ab2010-06-06 05:23:09 +020031
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010032#include "libbb.h"
33
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000034int yes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010035int yes_main(int argc UNUSED_PARAM, char **argv)
Erik Andersene49d5ec2000-02-08 19:58:47 +000036{
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000037 char **pp;
Erik Andersene49d5ec2000-02-08 19:58:47 +000038
Denis Vlasenko99912ca2007-04-10 15:43:37 +000039 argv[0] = (char*)"y";
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010040 if (argv[1])
Manuel Novoa III cad53642003-03-19 09:13:01 +000041 ++argv;
Erik Andersen31638212000-01-15 22:28:50 +000042
Manuel Novoa III cad53642003-03-19 09:13:01 +000043 do {
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000044 pp = argv;
Denis Vlasenko99912ca2007-04-10 15:43:37 +000045 while (1) {
Ron Yorstoncad3fc72021-02-03 20:47:14 +010046 fputs_stdout(*pp);
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000047 if (!*++pp)
Denis Vlasenko99912ca2007-04-10 15:43:37 +000048 break;
49 putchar(' ');
50 }
Manuel Novoa III cad53642003-03-19 09:13:01 +000051 } while (putchar('\n') != EOF);
Matt Kraai90f580a2000-09-22 03:45:34 +000052
Manuel Novoa III cad53642003-03-19 09:13:01 +000053 bb_perror_nomsg_and_die();
Erik Andersen31638212000-01-15 22:28:50 +000054}