🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #67

Re: shell problems

#67
From: Leif Jensen
Date: Wed, 04 Nov 1992 02:25
32 lines
1900 bytes
In article <dwhopkin.720837062@vela> dwhopkin@vela.acs.oakland.edu (Dave Hopkins) writes:
>This is possible if each nested backquote is quoted in a _nested_ manner.
>
>Example (in Bourne Sys V Shell):
>
>  echo `echo \`echo \\\`echo \\\\\\\`pwd\\\\\\\` \\\` \` `
>
>Although trivial, the above does work.  What puzzles me is that the number
>of required backslashes follows this pattern:  1 3 7 11 15 ...

Where does the 11 come from?  It is easy to show with an induction
argument that each number in the series is twice its predecessor plus
one, i.e. f(0) = 0, f(n) = 2 f(n-1) + 1 for n > 0.  This has the very
simple closed form f(n) = 2^n - 1 so the series goes 0, 1, 3, 7, 15, 31,
63, etc. 

Actually, I better explain why the recursion formula is obvious.  The
parts are interpreted in stages and each stage interprets backspace
escapes.  Each line down represents what the next subshell sees.

echo `echo \`echo \\\`echo \\\\\\\`pwd\\\\\\\` \\\` \` `
      echo ` echo \`  echo \\\`    pwd\\\`     \`   `
             echo `   echo \`      pwd\`       `
                      echo `       pwd`
                                   pwd

I tried to make it clear with the spacing.  This is exponential growth
so you can't carry it many more stages.

--
Leif Jensen
lhjensen@phoenix.princeton.edu
Technical Details
Message-ID: <1992Nov4.022511.15565@Princeton.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!gmd.de!jvnc.net!princeton!fish.Princeton.EDU!lhjensen
References: <1992Oct31.115106.552@latcs1.lat.oz.au> <dwhopkin.720837062@vela>

Show Full Headers
Complete Article Headers
Newsgroups: comp.unix.shell
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!gmd.de!jvnc.net!princeton!fish.Princeton.EDU!lhjensen
From: lhjensen@fish.Princeton.EDU (Leif Jensen)
Subject: Re: shell problems
Message-ID: <1992Nov4.022511.15565@Princeton.EDU>
Originator: news@nimaster
Sender: news@Princeton.EDU (USENET News System)
Nntp-Posting-Host: fish.princeton.edu
Organization: Princeton University
References: <1992Oct31.115106.552@latcs1.lat.oz.au> <dwhopkin.720837062@vela>
Date: Wed, 4 Nov 1992 02:25:11 GMT
Lines: 32