Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 09 Jul 2002 13:54:36 -0400
From:      Marty Landman <marty@face2interface.com>
To:        "James" <effdefender@earthlink.net>, "David Smithson" <david@customfilmeffects.com>, "FreeBSD-Questions" <freebsd-questions@FreeBSD.ORG>
Subject:   Re: How do I repeat a command N times?
Message-ID:  <5.1.0.14.0.20020709134313.089bfec0@mail.face2interface.com>
In-Reply-To: <001001c2276c$bacddcc0$0301a8c0@sys.gtei.net>
References:  <Pine.SGI.3.96.1020709115845.295966F-100000@y.dev.wamnet.com> <006801c2276b$f703f1d0$0801a8c0@customfilmeffects.com>

next in thread | previous in thread | raw e-mail | index | archive | help
At 10:19 AM 7/9/02 -0700, James wrote:

>I was messing with some basic script programs yesterday (though I haven't
>learned Perl yet), and it would not work (I had similar errors) unless I
>switched back to the Bourne shell.

too bad you haven't learned Perl or you could do this right from the 
command line :

perl -e '
$N = 607;
for(1..$N) {&do_something()}
'

The perl -e option says to execute an inline program - pretty much you're 
running an exec. The code though gets wrapped in those two single quotes 
you see. And "&do_something()" is calling a subroutine named do_something 
w/o any arguments; the subroutine code of course wasn't included here since 
you didn't say what you wanted to do. If you needed to pass the current 
iteration value to the subroutine then the call would be &do_something($_) 
since in Perl $_ is the Arg variable and by default contains the current 
loop iterator value.

Finally, if you put the program code into a file, so that you could for 
example run it off the crontab then if the pgm was in /perlcode/loop.pl 
you'd run it by saying

perl /perlcode/loop.pl

Marty

--
SIMPL WebSite Creation: http://face2interface.com/Home/Demo.shtml


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5.1.0.14.0.20020709134313.089bfec0>