From root@gits.dyndns.org  Thu Jun 17 23:00:57 2004
Return-Path: <root@gits.dyndns.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2CA7D16A4CF
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Jun 2004 23:00:56 +0000 (GMT)
Received: from ioskeha.hittite.isp.9tel.net (ioskeha.hittite.isp.9tel.net [62.62.156.27])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 132BD43D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Jun 2004 23:00:42 +0000 (GMT)
	(envelope-from root@gits.dyndns.org)
Received: from mail.gits.dyndns.org (28-216-118-80.kaptech.net [80.118.216.28])
	by ioskeha.hittite.isp.9tel.net (Postfix) with ESMTP id 4495F14B5B1
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 18 Jun 2004 01:02:06 +0200 (CEST)
Received: from mail.gits.dyndns.org (IDENT:wuar34dpkdntxkxq@localhost [127.0.0.1])
	by mail.gits.dyndns.org (8.12.11/8.12.11) with ESMTP id i5HMxaN9092445
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 18 Jun 2004 00:59:54 +0200 (CEST)
	(envelope-from root@gits.dyndns.org)
Received: (from root@localhost)
	by mail.gits.dyndns.org (8.12.11/8.12.11/Submit) id i5HMxaRa085055
	for FreeBSD-gnats-submit@freebsd.org; Fri, 18 Jun 2004 00:59:36 +0200 (CEST)
	(envelope-from root)
Message-Id: <20040617225935.GA10000@gits.dyndns.org>
Date: Fri, 18 Jun 2004 00:59:35 +0200
From: Cyrille Lefevre <cyrille.lefevre@laposte.net>
Reply-To: Cyrille Lefevre <cyrille.lefevre@laposte.net>
To: FreeBSD-gnats-submit@freebsd.org
Subject: standalone repeat(1) command
X-Send-Pr-Version: 3.113

>Number:         68062
>Category:       bin
>Synopsis:       standalone repeat(1) command
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 17 23:10:26 GMT 2004
>Closed-Date:    
>Last-Modified:  Sun Apr 25 21:20:04 UTC 2010
>Originator:     Cyrille Lefevre
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
ACME
>Environment:
System: FreeBSD gits 5.2-CURRENT FreeBSD 5.2-CURRENT #29: Mon May 31 01:35:59 CEST 2004 root@gits:/disk3/freebsd/current/obj/disk3/freebsd/current/src/sys/CUSTOM i386
>Description:
	the standalone repeat(1) utility inpired from the csh(1) one.
>How-To-Repeat:
	repeat 3 sync
>Fix:
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/share/man/man1/Makefile,v
retrieving revision 1.17
diff -u -I$Id.*$ -I$.+BSD.*$ -r1.17 Makefile
--- Makefile	20 Jan 2004 10:27:22 -0000	1.17
+++ Makefile	17 Jun 2004 22:22:34 -0000
@@ -61,7 +61,6 @@
 	builtin.1 read.1 \
 	builtin.1 readonly.1 \
 	builtin.1 rehash.1 \
-	builtin.1 repeat.1 \
 	builtin.1 sched.1 \
 	builtin.1 set.1 \
 	builtin.1 setenv.1 \

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	usr.bin/repeat/Makefile
#	usr.bin/repeat/repeat.1
#	usr.bin/repeat/repeat.c
#
echo x - usr.bin/repeat/Makefile
sed 's/^X//' >usr.bin/repeat/Makefile << 'END-of-usr.bin/repeat/Makefile'
X# $FreeBSD$
X
XPROG=	repeat
XWARNS?=	6
X
X.include <bsd.prog.mk>
END-of-usr.bin/repeat/Makefile
echo x - usr.bin/repeat/repeat.1
sed 's/^X//' >usr.bin/repeat/repeat.1 << 'END-of-usr.bin/repeat/repeat.1'
X.\" Copyright (c) 2004
X.\"	The Regents of the University of California.  All rights reserved.
X.\"
X.\" This code is derived from software contributed to Berkeley by
X.\" the Institute of Electrical and Electronics Engineers, Inc.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" 4. Neither the name of the University nor the names of its contributors
X.\"    may be used to endorse or promote products derived from this software
X.\"    without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\"     @(#)apply.1	8.2 (Berkeley) 4/4/94
X.\" From: src/usr.bin/apply/apply.1,v 1.14 2002/04/19 23:16:06 charnier Exp
X.\" $FreeBSD$
X.\"
X.Dd June 17, 2004
X.Dt REPEAT 1
X.Os
X.Sh NAME
X.Nm repeat
X.Nd repeat a command count times
X.Sh SYNOPSIS
X.Nm
X.Ar count
X.Ar command
X.Op Ar argument ...
X.Sh DESCRIPTION
XThe
X.Nm
Xutility runs the named
X.Ar command
Xwith optional
X.Ar argument ,
X.Pa count
Xtimes.
X.Sh DIAGNOSTICS
X.Ex -std
X.Sh SEE ALSO
X.Xr csh 1
X.Sh HISTORY
XThe
X.Nm
Xutility first appeared in
X.Xr csh 1 .
END-of-usr.bin/repeat/repeat.1
echo x - usr.bin/repeat/repeat.c
sed 's/^X//' >usr.bin/repeat/repeat.c << 'END-of-usr.bin/repeat/repeat.c'
X/*-
X * Copyright (c) 2004
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#include <sys/cdefs.h>
X__FBSDID("$FreeBSD$");
X
X#include <sys/types.h>
X#include <sys/wait.h>
X
X#include <err.h>
X#include <errno.h>
X#include <signal.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <unistd.h>
X
Xstatic int exec_cmd(const char *, char *const *);
Xstatic void usage(void) __dead2;
X
Xint
Xmain(int argc, char *const argv[])
X{
X	char *endp;
X	long count;
X	int rval;
X
X	if (argc < 2)
X		usage();
X
X	count = strtol(argv[1], &endp, 10);
X	if (errno == ERANGE || endp == argv[1] || *endp || count < 0)
X		errx(1, "%s: badly formed number.", argv[1]);
X
X	for (rval = 0; count > 0; count--)
X		if (exec_cmd(argv[2], &argv[2]))
X			rval = 1;
X
X	exit(rval);
X}
X
X/*
X * based on exec_shell() from apply(1).
X * exec_cmd --
X *      Execute a command using passed arguments.
X */
Xstatic int
Xexec_cmd(const char *command, char *const *argv)
X{
X	pid_t pid;
X	int omask, pstat;
X	sig_t intsave, quitsave;
X
X	if (!argv || !argv[0])           /* just checking... */
X		return(1);
X
X	omask = sigblock(sigmask(SIGCHLD));
X	switch(pid = vfork()) {
X	case -1:                        /* error */
X		err(1, "vfork");
X	case 0:                         /* child */
X		(void)sigsetmask(omask);
X		execvp(command, argv);
X		warn("%s", command);
X		_exit(1);
X	}
X	intsave = signal(SIGINT, SIG_IGN);
X	quitsave = signal(SIGQUIT, SIG_IGN);
X	pid = waitpid(pid, &pstat, 0);
X	(void)sigsetmask(omask);
X	(void)signal(SIGINT, intsave);
X	(void)signal(SIGQUIT, quitsave);
X	return(pid == -1 ? -1 : pstat);
X}
X
Xstatic void
Xusage(void)
X{
X
X	(void)fprintf(stderr, "usage: repeat count command [argument ...]\n");
X	exit(1);
X}
END-of-usr.bin/repeat/repeat.c
exit

>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, cyrille.lefevre@laposte.net
Cc:  
Subject: Re: bin/68062: standalone repeat(1) command
Date: Sun, 25 Apr 2010 23:18:13 +0200

 I'm not sure if we want this repeat(1) command, given that csh(1)
 already has it as a builtin and a simple shell function can do it in
 sh(1).
 
 repeat() {
         local i="$1"
         shift
         while [ "$i" -gt 0 ]; do
                 "$@"
                 i=$((i-1))
         done
 }
 
 This shell function will cause expansions and redirections to be
 evaluated exactly once, but so do the csh builtin and your proposed
 external command.
 
 The closest to the repeat command that fits in sh's model is
 ksh93/bash/zsh's arithmetic for command, e.g.
   for ((i=0; i<3; i++)); do sync; done
 I usually use the arithmetic for command or loops like in the shell
 function above.
 
 zsh also has a repeat compound command much like csh, except that it
 will evaluate expansions and redirections for each execution of the
 command.
 
 -- 
 Jilles Tjoelker
>Unformatted:
