Date: Sun, 29 Aug 1999 16:31:58 +0200 (CEST) From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de> To: freebsd-stable@FreeBSD.ORG Subject: Interesting ways to print 3000 spaces... Message-ID: <199908291431.QAA08474@dorifer.heim3.tu-clausthal.de>
next in thread | raw e-mail | index | archive | help
(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<a]salax" | dc In all of the above solutions, you can replace the "3000" with any other positive numeric value, to get the respective number of spaces. However, on my FreeBSD 2.2.8 box, the maximum value for the m4 solution is 4043 (stack overflow at 4044), and the dc solution coredumps for values > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199908291431.QAA08474>