* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)apply.c 5.2 (Berkeley) %G%";
* apply - apply a command to a set of arguments
* apply -2 cmp A1 B1 A2 B2 compares A's with B's
* apply "ln %1 /usr/fred/dir" * duplicates a directory
while(argc
>2 && argv
[1][0]=='-'){
defargs
= atoi(&argv
[1][1]);
fprintf(stderr
, "usage: apply [-#] [-ac] cmd arglist\n");
while(n
=docmd(argc
, argv
)){
fprintf(stderr
, "apply: command too long\n");
if(*q
++!=argchar
|| *p
<'1' || '9'<*p
)
fprintf(stderr
, "apply: expecting argument(s) after `%s'\n", argv
[argc
-1]);
q
= addarg(argv
[i
], q
-1);
if(defargs
!=0 && gotit
==0){
for(i
=0; i
<defargs
; i
++){
fprintf(stderr
, "apply: no shell!\n");
return(max
==0? (defargs
==0? 1 : defargs
) : max
+1);
char *shell
= getenv("SHELL");
if ((pid
= fork()) == 0) {
execl(shell
? shell
: "/bin/sh", "sh", "-c", s
, 0);
fprintf(stderr
, "apply: can't fork\n");
while ((w
= wait(&status
)) != pid
&& w
!= -1)