From owner-freebsd-stable Sun Aug 29 7:32: 6 1999 Delivered-To: freebsd-stable@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id 20C0814EA1 for ; Sun, 29 Aug 1999 07:32:02 -0700 (PDT) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.8.8/8.8.8) id QAA08474 for freebsd-stable@FreeBSD.ORG; Sun, 29 Aug 1999 16:31:58 +0200 (CEST) (envelope-from olli) Date: Sun, 29 Aug 1999 16:31:58 +0200 (CEST) From: Oliver Fromme Message-Id: <199908291431.QAA08474@dorifer.heim3.tu-clausthal.de> To: freebsd-stable@FreeBSD.ORG Subject: Interesting ways to print 3000 spaces... Organization: Administration Heim 3 Reply-To: freebsd-stable@FreeBSD.ORG MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: TIN [version 1.2 RZTUC(3) PL2] Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG (was: Re: Interesting way to crash a 3.2-stable box...) The Unicorn wrote in list.freebsd-stable: > On Sun, Aug 29, 1999 at 01:25:22AM -0400, Tim Vanderhoek wrote: > > On Sat, Aug 28, 1999 at 10:20:11PM -0400, Alex Perel wrote: > > > > > > print FOO " " x 3000; > > > > b$ print > > bash: print: command not found > > Hehehe, in perl of course ;-) olli@dao-lin-hay:~> perl zsh: command not found: perl This is probably the easiest way: jot -n -s "" -b " " 3000 And this would be a more portable approach (jot is not portable): dd if=/dev/zero bs=3000 count=1 | tr '\0' " " When using zsh, it can be done without exec'ing anything (only using shell-builtins): for f in {1..3000}; do echo -n " "; done It can be done in plain /bin/sh, too, but it's a bit more complicated... (line split for readability): x=" "; while :; do case ${#x} in 3000) break;; esac; x=" $x"; done; echo -n "$x" (Note, however, that ${#x} to get the length of a string is not portable. It _can_ be done in a portable way, but that requires a pretty lengthy shell script, which is available on request.) In m4, the solution is pretty straight-forward, using recursion (split for readability, this has to be on one line, and be sure to get the quoting right, and don't forget the space right befor the second-to-last closing parens -- it's the important one!): echo "define(iii,3000)define(\`foo',\`define(\`iii', decr(iii))ifelse(eval(iii<1),1,,\`foo' )')foo dnl" | m4 Now this one is really interesting (or rather, sick) -- create 3000 spaces with dc: echo "3000[[ ]P1-d0 95275... On a 4.0-current box, m4 behaves exactly the same, but dc goes much further and starts coredumping for values > 621350. (I wrote a shell script to find out those limits, using a binary search algorithm.) There would be another nice solution possible, but... printf '\t' | expand -3000 Expand refuses to use tab stops > 256. :-( I think I'll fix that and submit a PR. Regards Oliver PS: Yeah, I was bored... :-) -- Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany (Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de) "In jedem Stück Kohle wartet ein Diamant auf seine Geburt" (Terry Pratchett) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message