[Question]
  [
Given a positive integer nesting level `n` and string `s` of printable ascii characters( to `~`, output a program which, when run in the same language, outputs a program which outputs a program . . . which outputs the string `s`.
A total of `n` programs should be generated, all of which should be run in the same language as your answer.
Note: you may output programs or functions -- anything you are allowed by default as a submission.
You may input `s` with escaped characters, how a program or function in your language would usually input a string.
---
# Example
For example, given `n=1` and `s="recursion"`, a Python 2 program might output:
```
print "recursion"
```
Running this would output:
```
recursion
```
---
Given `n=2` and s="PPCG", a Python 2 program might output:
```
print "print \"PPCG\" "
```
Running this outputs:
```
print "PPCG"
```
Running this outputs:
```
PPCG
```
Related (+title inspiration): [One more LUL and I'm out](https://codegolf.stackexchange.com/questions/107323)
Also Related (in sandbox - now deleted, but can still be viewed with enough reputation): [Source Code Recursion](https://codegolf.meta.stackexchange.com/a/10273)
# Test Cases
Make sure that your code works for the following test cases (one per line):
```
n s
2 PPCG
4 Robert'); DROP TABLE Students;--
17 Deep
2 Spaces In Here
3 "Don't forget quotes!"
5 'Backt`cks might be a h`tch'
6 5%s
8 [Brackets]<Are>(Great){Usually}
3 !"#$%&'()*+,-./ 0123456789:;<=>?@ABCDEFGHIJKLMN
6 OPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
7 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
3 the quick brown fox jumps over the lazy dog
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
Ṿ¡
```
[Try it online!](https://tio.run/##y0rNyan8///hzn2HFv7//18pI1PpvzEA "Jelly – Try It Online")
```
Ṿ¡  Main link; left argument (text) is x, right argument (repetitions) is y
 ¡  Repeat y times:
Ṿ   Uneval x; produce code that outputs x
```
hehe builtins
[Answer]
# JavaScript (ES6), ~~47~~ 44 bytes
*Saved 3 bytes thanks to @HermanLauenstein*
Takes input in currying syntax `(n)(s)`.
```
n=>g=s=>`alert(atob("${btoa(--n?g(s):s)}"))`
```
### Example
```
f(2)('PPCG')
```
Will output:
```
'alert(atob("YWxlcnQoYXRvYigiVUZCRFJ3PT0iKSk="))'
```
Which will print:
```
'alert(atob("UFBDRw=="))'
```
Which will print:
```
'PPCG'
```
### Demo
A more complex example where `alert()` has been overridden so that intermediate results are printed to the console and automatically executed.
```
let f =
n=>g=s=>`alert(atob("${btoa(--n?g(s):s)}"))`
alert = s => { console.log(s); try { eval(s); } catch(e) {} }
alert(f(5)("'Backt`cks might be a h`tch'"));
```
---
# Alternate version, 40 bytes
*Suggested by @Shaggy*
This one returns an anonymous function instead of a full program.
```
n=>g=s=>`_=>atob("${btoa(--n?g(s):s)}")`
```
[Answer]
## sh + coreutils, 31 bytes
```
yes exec sed 1d \$0|sed $1q;cat
```
Takes `n` as a command-line parameter and `s` on STDIN.
[Answer]
# [Python 2](https://docs.python.org/2/), 40 bytes
```
f=lambda r,t:r and"print%r"%f(r-1,t)or t
```
[Try it online!](https://tio.run/##TchBCoAgEEDRfacYBkQFW1S7oLOEYaJgKsNEdHqjVm0@vF9vDiWPrfkl2WNzFsjwTGCzw0oxsyAUXlE/GNaFgNt3lVdvyV5rzPVkpbWBv3SbOolhT6nAVSg5lA8 "Python 2 – Try It Online")
-4 bytes thanks to xnor
[Answer]
# Haskell, 17 bytes
As of when I write this, this is the shortest answer for a *non-golfing-specific* language.
It is a function which takes `s` and `n` in that order, and returns the result or the source code of an expression which, when evaluated, returns the next source code.
```
(!!).iterate show
```
Argument for why this counts:
1. Solutions are allowed to be functions.
2. Their outputs are allowed to be functions.
3. Those functions have no parameters.
4. In Haskell, since it is lazy and everything-is-curried, the most natural — for practical programming purposes — definition of a 0-parameter function is the same as its result; the closest alternative, a 1-parameter function which ignores the parameter, is silly.
If `f` is given `PPCG` and `2` as its parameters, the result is the text `"\"PPCG\""` (first generated function), which when evaluated returns the text `"PPCG"` (second generated funtion), and when that is evaluated it returns `PPCG`.
Thanks to [nimi](https://codegolf.stackexchange.com/users/34531/nimi) for suggesting a shortening. 
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), ~~24~~ 23 bytes
-1 thanks to ngn.
This is a full program which prompts for `s` and then for `n` and prints to STDOUT.
```
''''{⍺,⍨⍺,⍵/⍨1+⍵=⍺}⍣⎕⊢⍞
```
[Try it online!](https://tio.run/##VVDJUsJAEL3PV7S4RFTcEDcUJYCAgokB3BeGMCZIyODMREXEq5ZVePPqQS/@gBc/Jz@CQS@hL939lq6uh5tWqNrCFjV67vNTnjLSk7xqu92fKbf79d@@Z7xxbtIb1j2g43Y/3dc39@XD7b73XT34q74ZqWoijeaRD9FohTAhBaOQ1BQVinE5l4KCcKrEFjwaCqEFv7rQxDrhkLUhQ7x14FIgSW1JwCVlBhFw7VBB@FAAhf0aScZ6XZT1OodGzTAFVAhgMMtCNyUU8Ssjoxwt@oETmXleIvjZWpyR2HiaESyC7RJ3sGW1OmjZLx4KDI@MjknjwYnJqdD0DMzOzYcXIotLyyur0bX12MZmXE4kU1vpTHZ7J5ffHXxSUfe0QrG0f3B4dHxyenZ@UcYVvUouDbN2VbcaNm1eMy6cm9u71n37ofM4@Gcxk4K9UjaxA7KmHOzClnII26W8WgBlP6VBn87Fj48gqaTRkt8oTOKlVtPrUGH01vaCvIMrp9HkQG8Igz5t4fsWVKmBwr8 "APL (Dyalog Unicode) – Try It Online") (the 17 Deep case is omitted as it exceeds TIO's output limit – works offline)
`⍞` prompt for `s`
`⊢` yield that (to separate `⎕` and `⍞`)
`''''{`…`}⍣⎕` prompt for `n` and apply this lambda with a single quote as left argument that many times. `⍺` stands for the left argument (the quote) and `⍵` is stands for the right argument (the input text):
 `⍵=⍺` Boolean where the text is equal to a quote
 `1+` add one
 `⍵/⍨` replicate each character of the argument the corresponding number of times
 `⍺,` prepend a quote
 `⍺,⍨` append a quote
This works because strings in APL are `'` delimited and single-quotes in strings are doubled, while no other characters need escaping.
---
Dyalog APL also ships with a utility (`⎕SE.Dyalog.Utils.repObj`) that generates an APL expression which evaluates to its argument (similar to [Jelly's uneval](https://codegolf.stackexchange.com/a/143923/43319)). The following program is therefore equivalent to the above, but works for *all* arrays:
```
⎕SE.Dyalog.Utils.repObj⍣⎕⊢⎕
```
[Try it online!](https://tio.run/##bVE9SwNBEO3vV4zVJYUBTf6AqKCgpEgsLDd3E29ls7vsziYEEaxUhBMbSy0U/GH3R@LsfcAV2eLgZua9N@@NsOow3wpl7nbV68u1cbir3j9n56Ozuji6Ian8yKGdLu6r8pd71dsPf@P0riq/YH45BRe0B6EBV5a24NF7aTR4AxuEQqwRyIA1NihBCJJgKZ0nGGhDoBFzzEFqEKCNWwkFZrlUUmPHM0ygfix6ept6oShtC6xOhfSQGSvRRw4qEBzDTHAZV1g@8vflfT3TrdhSPzyiFguFs5OreZ94P2gjqQChVFMM1irJGoGDksR7tJwxyiTG9fwxOIJjGA8n6QUqZdJWAbPC1BRS20AgfEyGRR1mKNeYJ@Okc16@V@V3ZxnXQoUYZGs2KAKjM6ye/pI0TVsxmAD/tIrN28tGG9lC@8AOth9SOMYcJD1AM5/ELh@Vu1CYTb1gc@ppoOixPitblDlqnuJbUxOBEp7@AQ "APL (Dyalog Unicode) – Try It Online")
[Answer]
# Firefox JavaScript, ~~41~~ 35 bytes
```
f=(s,n)=>"_=>"+uneval(--n?f(s,n):s)
```
Firefox has a nice `uneval`, which does what it sounds like - unevals a given object, in this case - string.
[Answer]
# Java 8, ~~95~~ 93 bytes
```
String c(String s,int n){return"v->\""+(n-->1?c(s,n).replaceAll("[\\\\\"]","\\\\$0"):s)+'"';}
```
-2 bytes thanks to *@Lynn*.
Escaping special characters is so annoying in Java..
[Try it here](https://tio.run/##LY4xa8MwFIR3/4pXUYhEbJNApxhSsqVDp4yOB1V@BKXKk5GeHUrwb1dl8E3HHcd3dz3pyg9I9/43GadjhG9t6VUARNZsTbpwsHQDI1cTS0sMpF4BeQwkpup4FWIrqaqO@08jY0mqDjg4bfDknBTtdZHoRCkW874T6hDVdiM2zZyaIpOG8cdZswJh8raHRz6xEtsOtFoOAVz@IuOj9iPXQ65YGqnbXVcC4RO@iPGGISf7TinV5MVczCmd0TkPTx9c/5Y@/gE) and [try the resulting method here](https://tio.run/##NU5BDoIwELzzirWncoAPED17kYuJF/FQSzXFsiV0qTGGt9cWYZOZzc4mM9MJLwo7KOzaV5BGOAcnofGbAWgkNT6EVFCnE@BMo8YnSH6xugWfV1Gds0iOBGkJNSDsgy8OLKJZqNlWGnZUxlh429G0u01bwFioktEw3U00Wv18iuljG/5Pvt5A5GuVjyPVl3aicogv4lhKjpMx@dpqDj8).
**Explanation:**
```
String c(String s,int n){  // Method with String and int parameters and String return-type
  return"v->\""+           //  Return literal "v->" + a leading double-quote +
   (n-->1?                 //   If `n` is larger than 1:
     c(s,n)                //    Recursive-call,
      .replaceAll("[\\\\\"]","\\\\$0")
                           //    with all double-quotes ('"') and slashes ('\') escaped
    :                      //   Else:
     s)                    //    The input String
   +'"';                   //   + a trailing double quote
}                          // End of method 
```
Additional explanation for the regex replacement:
```
.replaceAll("[\\\\\"]","\\\\$0")
.replaceAll("        ","      ")  // Replace the match of the 1st String, with the 2nd
             [      ]             //  One of these inner characters:
              \\\\                //   Escaped slash ('\')
                  \"              //   Escaped double-quote ('"')
                                  //  And replace them with:
                        \\\\      //   Escaped slash ('\'),
                            $0    //   plus found match
```
Why all these slashes?
```
\   →  \\       // Escapes a single slash for the regex
\\  →  \\\\     // Escapes both regex-escaped slashes for the String
"   →  \"       // Escapes a double-quote for the String
```
[Answer]
# [Underload](https://github.com/catseye/stringie), 11 bytes
```
(a(S)*)~^^S
```
[Try it online!](https://tio.run/##K81LSS3KyU9M@a/hX1pSUFqiqWGlZaWl@V8jUSNYU0uzLi4u@P9/AA "Underload – Try It Online")
Input needs to start on the stack, with the number on top in the form of a [church numeral](https://esolangs.org/wiki/Underload#Numbers). I don't know if this is a valid input method, but the specification has no input, and placing input to the top of the stack seems like a stranded method used in such languages.
[Answer]
# [R](https://www.r-project.org/), 62 bytes
```
f=function(n,s){"if"(n,{formals(f)$n=n-1;formals(f)$s=s;f},s)}
```
[Try it online!](https://tio.run/##K/r/P802rTQvuSQzP08jT6dYs1opM00JyKpOyy/KTcwp1kjTVMmzzdM1tEYSKLYttk6rBaqu/Z@mYayjZKygGKOkrKKqpq6hqaWto6unr2BgaGRsYmpmbmFpZW1ja2fv4Ojk7OLq5u7h6eXt4@unpKkBhlxpGqY6CkrqTonJ2SUJydnFCrmZ6RklCkmpCokKGQklyRnqMKUg@B8A "R – Try It Online")
Call it like so: `f(n,s)` followed by `n` copies of `()`
A named function; returns an anonymous function. All it does is modify the default values of the `formals` of `f`, allowing the resulting function to be called (and then the result of that called, `n` times). when `n` reaches `0`, it returns `s`.
R is actually not too bad at escaping! It uses C-style escaping, so you just have to take the input, replace `"` with `\"` and `\` with `\\`, and then wrap the whole thing in `" "`.
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 5 bytes
```
~{`}*
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/v646oVbr/3@lgABndyUFIwA "GolfScript – Try It Online")
[Answer]
# [QuadR](https://github.com/abrudz/QuadRS), 8 bytes
Simple translation of [ngn's answer](https://codegolf.stackexchange.com/a/144094/43319).
Takes `n` as argument and `s` as Input.
```
^|'|$
'&
```
[Try it online!](https://tio.run/##KyxNTCn6/z@uRr1GhUtd7f9/JZf8PPUShbT8ovTUEoXC0vyS1GJFJS5FJWUVVTV1DU0tbR1dPX0FA0MjYxNTM3MLSytrG1s7ewdHJ2cXVzd3D08vbx9fP66SjFSg5szkbIWkovzyPKB5FQpZpbkFxQr5ZalFCiDpnMSqSoWU/PT/xgA "QuadR – Try It Online")
PCRE **R**eplace all instances of
`^|'|$` Beginning of line OR Quote OR End of line
`'&` with a Quote and the entire match
The Argument specifies how many times to repeat the transformation.
[Answer]
# Excel VBA (32-Bit), 67 Bytes
*Version Restricted to 32-Bit Excel VBA because `2^i` evaluates without error in 32-Bit VBA, but not in 64-Bit VBA*
Anonymous VBE immediate window function that takes inputs `n` and `s` from from ranges `[A1]` and `[B1]` and outputs an anonymous function that when evaluated down to only a terminal (after `n` iterations) outputs only `s` as that terminal 
```
For i=0To[A1-1]:q=q+"?"+String(2^i,34):Next:?q[B1]Replace(q,"?","")
```
### Sample Input / Output
```
[A1:B1]=Array(7, "PPCG")
For i=0To[A1-1]:q=q+"?"+String(2^i,34):Next:?q[B1]Replace(q,"?","")
?"?""?""""?""""""""?""""""""""""""""?""""""""""""""""""""""""""""""""?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""PPCG"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
?"?""?""""?""""""""?""""""""""""""""?""""""""""""""""""""""""""""""""PPCG"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
?"?""?""""?""""""""?""""""""""""""""PPCG"""""""""""""""""""""""""""""""
?"?""?""""?""""""""PPCG"""""""""""""""
?"?""?""""PPCG"""""""
?"?""PPCG"""
?"PPCG"
PPCG
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 2 bytes
```
(q
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIocSIsIiIsIjNcbkNHQ0MiXQ==)
N times, uneval the string.
[Answer]
# Pyth, 21 bytes
```
L++NsXbJ,N\\+L\\JNyFz
```
[Try it here.](http://pyth.herokuapp.com/?code=L%2B%2BNsXbJ%2CN%5C%5C%2BL%5C%5CJNyFz&input=2%0APPCG&debug=0)
Unfortunately the recursive function (not full program as above) is longer (24 bytes):
```
M?GgtG++NsXHJ,N\\+L\\JNH
```
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 19 bytes
```
'^|''|$'⎕r'''&'⍣⎕⊢⍞
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ooz3tv3pcjbp6jYr6o76pRerq6mrqj3oXA9mPuhY96p0HUvI/jStRXT1JPRkoy2UEAA "APL (Dyalog Classic) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 34 bytes
`%p` is a Ruby-specific printf flag that gets the `inspect` value of its argument, similar to `%r` in Python. `$><<` means print.
```
f=->n,s{"$><<%p"%(n>1?f[n-1,s]:s)}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y5Pp7haScXOxka1QElVI8/O0D4tOk/XUKc41qpYs/Z/QWlJsUJadHpqSbFeSX58po4CiBn735hLySU/T71EIS2/CCiiUFiaX5JarKgEAA "Ruby – Try It Online")
]