text:
Script that outputs a script that prints a given input
Write a piece of code that takes a string as input, and outputs a piece of code in the same language that, when run, will output the initial input string.
It must be able to handle any combination of characters A-Z, a-z, and 0-9.
Example in Python:
import sys
print "print('" + sys.argv[1]  + "')"

Given the input of testing123, it will return print('testing123').
Since this is code-golf, the shortest answer in bytes will win.

Can it be a function?

@manatwork (S)he edited it just now.

Must input be a string? Or can it be an integer?

Must be able to handle both integer and string inputs.

@Quartzic what if the language can't do integer inputs, but only inputs as strings? (aka, you would take, for example, "1" for an integer)

You should edit that into the challenge, which only mentions strings. Note, though, that requiring solutions to be able to handle both types of input would invalidate at least one of the existing answers, probably more.

So only A-Z, a-z, and 0-9 can appear in the input?

@ConorO'Brien Your code only has to handle A-Z, a-z, and 0-9 in the input to be deemed valid. What you do with invalid inputs is up to you.

Can we have arbitrary strings around the intended string?

What about zero length input strings ? Is it considered as invalid input ?

Very similar to this, but more broad.

Can we output a function as per the defauts on meta?

pl, 0 bytes
Code:

Try it online!
Explanation:
An empty program in pl is simply a cat program, outputting the exact same as the input.
In pl, all ASCII characters are essentially variables, but when the variable doesn't exist (yet), pl assumes that they are part of a string.

I knew there was a language like this, couldn't find it though :(

In the same vein, see Cat, which is an interpreted language like Python. Most modern Linux distros ship with a cat interpreter. ;)

This solution also works for /// if you consider input to be appended to the program source code (since /// has no mechanism for input). /// is one of many languages (I think) where alphanumeric characters at the beginning of the program are simply output.

Can you post the ungolfed version? ;)

brainfuck, 56 55 33 bytes
1 byte saved thanks to Gravitron, and 22 bytes saved thanks to Jo King!
--[>+<++++++],[[->.<]>+++.--.-<,]

Try it online!
Output requires an interpreter that wraps on memory underflow and has EOI=0. TIO has such an interpreter.
Explanation
--[>+<++++++] initializes the tape with a single +.
The input loop:
,[[->.<]>+++.--.-<,]
,                     take input
 [                ,]  while input is nonzero:
  [->.<]                  output `+` input times
        >+++.             output `.` (`+` + 3)
             --.          output `,` (`.` - 2)
                -<        restore `+` and move back to input

Other solutions
Each line is its own solution.
+++[>+++++<-]>[>++++>+++<<-]>>-->,[[-<.>]<+++.---<.>>,]
--[>+<++++++],[[->.<]>+++.++++++++++++++++.-------------------<,]
++++++++++[>++++++>++++>++++<<<-]>>+++>++++++>,[[-<<.>>]<.<<.>>>,]
++++++++++[>++++++>++++>++++<<<-]>++>+++>++++++>,[[-<<.>>]<.<<.>>>,]

+1. I don't know Brainfuck, but I can't imagine trying to solve a problem like this with it.

You can save 1 byte by replacing the +++++++++++++++ with +++[>+++++<-]> (From brainfuck constants)

@Graviton Oh, cool, thanks

you didn't replace it in the explanation

You don't know Brainfuck? I'll teach you in one comment! We start on a tape of 0's, with a pointer to a value. + increments the value, - decrements the value, > moves the pointer right, < moves the pointer left, , reads input to the pointer as an ASCII character, . outputs the value of the pointer as an ASCII character, [ starts a loop, and ] jumps to the corresponding [ if the value of the pointer is not 0. I'm bad at explaining, but that's how easy Brainfuck is. And Nice golf Conor!

Can't you use , instead of .? Try it online!

@JoKing That's a smart idea, using EOF=0 to get a new cell value. Nice!

Mornington Crescent, 27640 bytes
Take Northern Line to Moorgate
Take Circle Line to Moorgate
Take Circle Line to Westminster
Take Circle Line to Hammersmith
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Victoria
Take Circle Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Bayswater
Take District Line to Barons Court
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Cannon Street
Take Circle Line to Moorgate
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Mile End
Take District Line to Barking
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Bakerloo Line to Paddington
Take Circle Line to Royal Oak
Take Circle Line to Tower Hill
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Liverpool Street
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to East Ham
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Sloane Square
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take Circle Line to Cannon Street
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to East Ham
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Plaistow
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Liverpool Street
Take Circle Line to Bank
Take Circle Line to Liverpool Street
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Dagenham East
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Victoria
Take Circle Line to Bank
Take Circle Line to Victoria
Take Circle Line to Hammersmith
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Victoria
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Elm Park
Take District Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take Central Line to Northolt
Take Central Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Barons Court
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Wimbledon
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Mile End
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Bakerloo Line to Waterloo
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Paddington
Take Circle Line to Bank
Take Circle Line to Victoria
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Victoria
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Circle Line to Victoria
Take Victoria Line to Euston
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Bank
Take Central Line to Northolt
Take Central Line to Bank
Take District Line to Southfields
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Upminster
Take District Line to Ravenscourt Park
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Upminster
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Old Street
Take Northern Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Mile End
Take Central Line to Theydon Bois
Take Central Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Old Street
Take Northern Line to Bank
Take Circle Line to Bank
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Acton Town
Take Piccadilly Line to Cockfosters
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take District Line to Elm Park
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to East Ham
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Elm Park
Take District Line to Bank
Take Central Line to Chancery Lane
Take Central Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take District Line to Plaistow
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Brent Cross
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Southfields
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Elm Park
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Elm Park
Take District Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Royal Oak
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barons Court
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Royal Oak
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Farringdon
Take Circle Line to Paddington
Take Circle Line to Paddington
Take District Line to Southfields
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Embankment
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to East Ham
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to East Ham
Take District Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to West Ham
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take District Line to Barons Court
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Moorgate
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Central Line to Chancery Lane
Take Central Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Paddington
Take Circle Line to Westminster
Take Circle Line to Paddington
Take District Line to Plaistow
Take District Line to Bank
Take Circle Line to Moorgate
Take Circle Line to Hammersmith
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Bank
Take Circle Line to Paddington
Take Circle Line to Westminster
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Aldgate
Take Circle Line to Temple
Take Circle Line to Hammersmith
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Bank
Take Circle Line to Westminster
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Temple
Take Circle Line to Bank
Take Circle Line to Bayswater
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bayswater
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Embankment
Take Circle Line to Hammersmith
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Embankment
Take Northern Line to Angel
Take Northern Line to Bank
Take Central Line to Marble Arch
Take Central Line to Bank
Take Circle Line to Bank
Take Circle Line to Westminster
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Embankment
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Hammersmith
Take Circle Line to Embankment
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take District Line to Acton Town
Take District Line to Acton Town
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Holborn
Take Central Line to Holborn
Take Central Line to Bank
Take Circle Line to Hammersmith
Take District Line to West Ham
Take District Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Aldgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to King's Cross St. Pancras
Take Victoria Line to Seven Sisters
Take Victoria Line to Euston
Take Victoria Line to Euston
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Stepney Green
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Stepney Green
Take Hammersmith & City Line to Moorgate
Take Circle Line to Moorgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to Moorgate
Take Circle Line to Moorgate
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take District Line to East Ham
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to East Ham
Take District Line to Tower Hill
Take Circle Line to Bank
Take District Line to West Ham
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Angel
Take Northern Line to Bank
Take Circle Line to Moorgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Barbican
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Moorgate
Take Circle Line to Bank
Take Northern Line to Morden
Take Northern Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take District Line to Mile End
Take District Line to Embankment
Take Northern Line to Kennington
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Liverpool Street
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Metropolitan Line to Croxley
Take Metropolitan Line to Aldgate
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to West Brompton
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Acton Town
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take District Line to Mile End
Take District Line to Acton Town
Take District Line to Acton Town
Take Piccadilly Line to Hounslow Central
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent

Try it online!
Explanation
First, a quick refresher on Mornington Crescent:

each station can either hold a string of arbitrary length or a bigint
there's also an accumulator which also holds a string or a bigint
all stations start with their own name as their value
at the beginning, the accumulator contains your program's input
each time you go to a station, the station's value and the accumulator are swapped
some stations are special and override this behavior
the line you use to get to a station doesn't matter
you start at Mornington Crescent
to end the program, you go to Mornington Crescent too
at the end, the value of the accumulator is printed

Since printing strings is hard (see Martin Ender's Mornington Crescent "Hello, World!" program), we will need a simple template that can be used to output generic strings. Since the length of the generated programs don't matter, I've settled on this:
Take Northern Line to Bank
Take Northern Line to Bank
Take District Line to Paddington

We'll need to generate each character separately and concatenate them, since the substring approach used by Martin is much harder to implement in the general case. Paddington is the station that performs string concatenation. When you arrive at Paddington, the following happens:
accumulator, paddington = paddington + accumulator, accumulator

This behavior is used to initialize Paddington to the empty string that's assumed to be the input.
Take District Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Euston
Take Victoria Line to Euston
Take Northern Line to Bank

Go to Seven Sisters, which sets the accumulator to 7, and store it in the Bank. The Bank is the only way to copy values - Hammersmith is a readonly copy of Bank's value.
Take District Line to Hammersmith
Take District Line to Cannon Street
Take District Line to Hammersmith
Take District Line to Cannon Street
Take District Line to Bank

Divide 7 by 7 to get 1, a divisor of all ASCII values we need to support.
Take District Line to Hammersmith
Take District Line to Upminster

For each character, start by copying the 1 to Upminster.
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster

Add more ones as necessary.
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take District Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Bakerloo Line to Paddington
Take Bakerloo Line to Paddington
Take Bakerloo Line to Charing Cross
Take Northern Line to Embankment

Finish up by going to Upminster only once, to keep the new value in the accumulator instead of storing it again. Take it to Charing Cross to turn the ASCII value into a character and append it to the string. The last two lines are there because I've misread the specification, so I'll stop here and golf my program down first.

(disclaimer: I've just learnt this language) About the exact same approach I can think of (7/7=1). But why don't you just set Upminister only once at the beginning of the program?

@user202729 How would that work? / Fun fact: repeated Take District Line to Upminster lines calculate the fibonacci sequence

Looks like I misunderstood the spec. But that's exactly what it says there... someone need to edit the wiki.

Jelly, 1 byte
Ṿ

Woo builtins!
The builtin Ṿ unevals the input.
Try it online!
A more interesting one:
⁾“”j

Joins the string "“”" by the input.
Try it online!

For the second one I think you can do ”“; for -1.

Charcoal, 1 byte
θ

By default, a string of ASCII characters  .. ~ simply prints itself, so it just remains to print the input.

I was going to add this same answer. :-)

@CarlosAlejo Well it's not as if there was a different answer...

Well there is :P

@ASCII-only Touché!

C (gcc), 89 87 58 56 bytes
Saved two bytes thanks to Jakob!
main(a,c)char**c;{printf("main(){puts(\"%s\");}",c[1]);}

Try it online!

"It must be able to handle any combination of characters A-Z, a-z, and 0-9." You might want to go with the escapes strategy after all.

@Jakob yeah I just read that :/, thanks

I had also just finished writing the escaper regex for a Java solution when I read that. Bummer.

@Jakob Yeah, same for me, but with eacal. RIP

You can use puts in the printed program to save 2 bytes, right? Or is it a problem that it appends a newline?

Japt, 2 bytes
iQ

Try it online!
i is a function that inserts a specified string at a specified index into the input. Q is a variable that defaults to a quotation mark ", and since there's no index given, this defaults to 0. The end result is a quotation mark inserted at the beginning of the string, which Japt auto-finishes when running.
This works on strings containing anything except ", {, or \, though of course the string is guaranteed to consist of alphanumeric chars so this doesn't matter.

Python 2, 22 bytes
print'print%r'%input()

Try it online!

An alternate 22 byte solution is print'print'+\input()``.

This wouldn't work. input in Python 2 is equivalent to eval(raw_input()). So it has to be a pythonic expression for it to work.

Yes, that is allowed. ---Let me find the appropriate meta...--- Aha, found it.

21 bytes

MATLAB / Octave, 15 bytes
@(t)['disp ',t]

Try it online!
I completely overlooked the fact that the program only needs to handle alphanumeric characters, or, importantly, does not need to handle space characters. This means we can use the 'command' syntax, which uses significantly less bytes.
MATLAB, 27 bytes
For completeness, here's a version that can handle arbitrary input:
@(t)['disp(',mat2str(t),41]

Defines an anonymous function taking the string t, and converts it to the program. Curiously, this does not work in Octave, which seems to have different ideas of what mat2str should do.

I can't test this, but I think: @(t)['disp ',mat2str(t)] should work...?

@StewieGriffin That doesn't work because mat2str adds quotation marks, which are not necessary in command syntax. I had the function syntax combined with mat2str to handle spaces in the input, but on rereading the challenge, that's not actually necessary, cutting the bytecount nearly in half. Thanks!

I thought quotation marks was necessary if there were spaces in the input but I might be wrong. I didn't notice that the input was only alphanumeric either...

Like this (ungolfed).

@StewieGriffin You are right, I misjudged the way command syntax works. However, command syntax seems to be full of suprises: Try it online!

PowerShell, 9 Bytes
"'$args'"

single or double quotes in powershell can be used to contain strings, but only double-quotes allow variable expansion.
with an input of foo this will output 'foo' which is a valid powershell program which outputs foo

Befunge-98 (FBBI), 21 16 12 bytes
-5 bytes thanks to NieDzejkob
-4 bytes thanks to Jo King
#,~'',,',,'@

Try it online!
Outputs 't,'e,'s,'t,@ for an input of test
How?
Initially the pointer moves East:
#,           # skips the next instruction
  ~          push a byte of input
   '',       push ' and print it
      ,      print the byte of input
       ',,   push , and print it
          '@ push @ to the stack

If there is no more input left, ~ reverses the direction of the pointer:
 ,           print @
#            skip nothing
           @ terminate

Emojicode, 88 bytes
➡❌❌

Try it online!
Input:
anyString

Output:
anyString

Script Output:
anyString

D, 92 89 bytes
void main(){import std.stdio;write(`void main(){import std.stdio;"`~readln~`".write;}`);}

Try it online!

V, 2 bytes
ii

In Vim, i changes to insert mode and allows inserting text.  In this case, it just inserts the i in front of the input text (to create the second program).  V is Vim compatible, but adds an implicit <esc> to the end of the program, so I don't need to worry about it here.

Cubically, 87 bytes
U3D1R3L1F3B1U1D3~:7+1(-1@3(-1%1)6:1+3111@6%1-31111+004@6:1+11111%6:1+45@6:1-1%6~:7+1)6

Try it online!
A port of my answer here. There already existed a challenge to take input and output Cubically code that produced that input, and I had an answer in Cubically so... profit?

Save a few bytes - remove the arguments from %6s and @6s; they can now be called implicitly. (You can also do that on your answer on the cubifier thread.)

QBIC, 7 bytes
?@?@`+;

Explanation
?           PRINT on the screen
 @  `       a literal
  ?@         question mark and at
     +;     and append the input

Sample run
Command line: lala
?@lala

The output is a string literal containing the input, preceded with a PRINT command.

Batch 11 bytes
I'm sure there's away to get it smaller, but this is pretty small.
set/p=echo

The breakdown:
set             ::Define new variable
   /p           ::Create prompt
     =          ::Define a variable in prompt
      echo      ::Prompt begins with 'echo '

In English:
The user is asked for input with a leading phrase echo. Then the user may type in whatever, and the program terminates (e.g; echo hello world!). This leaves us with a program that when ran, will output hello world!.
Yes, the whitespace is supposed to be there

I don't know batch (and this is from long ago), but this looks wrong. Wouldn't the echo portion be text echoed to the console and not program output?

@Jakob suprosingly no, it's essentially functionally equivalent to the python example given in the initial challenge.

Oops--what I meant is that I doubt the program outputs the text the user types. It's probably just echoed to the console, right?

@Jakob Right, which is equivalent to printing. The example prints a print function while mine echos an echo function.

OK, but the example prints the entire program to standard out. Your program prints only echo  to standard out. In fact, (I assume) if input comes from a file or pipe, all you'd see is the prompt. Has that kind of output been allowed?

SmileBASIC, 21 bytes
Maybe this is cheating...
LINPUT"?"+CHR$(34);S$

Asks for input with the prompt ?". (? is short for PRINT, and closing quotes are not required). So the "output" program is ?"<text>

Python 2, 17 bytes
'print%r'.__mod__

Try it online!

This fails for 1

@NoOneIsHere the challenge requires to take a string as input. If you pass '1' to the function it correctly outputs print'1'

Oh, I'm sorry. I didn't notice that.

Brain-Flak, 92 68 bytes
-22 bytes thanks to Wheat Wizard
Includes +2 for -cr
{<>(((((()()()()()){}){}){})())<>{({}[()])<>((({}[()])()))<>}{}}<>

Try it online!
# For every character
{

   # Put ")(" on the off stack
   <>(((((()()()()()){}){}){})())<>

   # for 0 to the ASCII value of this character
   {({}[()])

      # Replace the ")" with "(" and add "))"
      <>((({}[()])()))<>

   # End for
   }{}

# end for and switch to the off stack for printing (in reverse order because of -r)
}<>

Pyth, 2 1 byte
z

Try it online!
Just outputs the input. Requires strings to be in quotes.
-1 byte thanks to KarlKastor

Can you just do +\"? (\x char literal + implicit Q)

@ETHproductions Even better, +N

Nice, I don't know Pyth quite that well :-)

SOGL V0.12, 2 bytes
$+

Try it Here! (expects input on stack so , is added for ease-of-use)
$ pushes ”, + joins that after the input on the stack.

You can use `"` for ".

@NoOneIsHere yeah, that makes sense.. Used it everywhere else except where it's the most useful .-.

Perl 6, 19 bytes
say "say "~get.perl

Try it
This should work for any Unicode input in NFC

Can you remove the space?

@NoOneIsHere Removing either space would result in a two terms in a row error. Perl 6 has significant whitespace, but it is only significant in that it either has to be there, or has to not be there. (there are ways of opting out of both though)

8th, 34 37 bytes
Code
: f >s "\"" tuck s:+ s:+ " ." s:+ . ;

Example
ok> "Print 42" f
"Print 42" .
ok> "Print 42" .
Print 42

PHP, 12 bytes
<?=$argv[1];

Try it online!
This is to be run from the command line with the input as the parameter argument. And yes, it simply outputs the input string—but that is valid PHP: anything outside the <?php ?> delimiters is output unprocessed.
Here is the script produced by the 'testing123' input in action as a demonstration: Try it online!

this won't work quite right if the input string contains <?php, mind you ;)

@Andrea Read the question: "It must be able to handle any combination of characters A-Z, a-z, and 0-9." So '<?php' is invalid input…

aw, that's too easy :(

Haskell, 2 bytes
id

id returns it's argument unchanged.
id "abc" returns "abc" which evaluates to itself, which is a valid output method according to or standard rules. id is polymorphic and works for all kind of input types, so it also works for integer inputs.
The challenge requires to "output a piece of code". As @TannerSwett point out in a comment, the output of id is not valid Haskell source code, but a Haskell value or function that can be evaluated further, so it might also qualify as "code". If "code" means "source code" then we have a 4 byte answer
Haskell, 4 bytes (outputs source code)
show

Doesn't id "abc" really evaluate to the string abc (which would normally be written with quotation marks to indicate that it's a string), rather than to the string literal "abc"? I would think that "interpreting the output of id "abc" as a Haskell expression" would mean interpreting abc, not "abc", as an expression.

@TannerSwett: hmm, hard to tell. The challenge requires to "output a piece of code". If "code" means "source code", the you're probably right. If "code" means something that can be evaluated then I think id is a valid answer. I'll edit this in my answer.

JavaScript ES6, 25 bytes (outputs code to "standard output")
s=>alert(`alert('${s}')`)

JavaScript ES6, 23 bytes (returns code, that outputs to "standard output")
s=>`alert('${s}')`

JavaScript ES6, 14 bytes (returns a function, that returns the result)
s=>`_=>"${s}"`

You're missing the quotation marks in your last solution, which should be your submitted solution as it's the shortest of the 3.

@Shaggy Right, let me add i

You swapped string literals in your last function (and now it throws syntax error). Side note: it is not returning a function, it is returning a string which represents a function which returns the input.

MATL, 2 bytes
&D

Try it online!
Simply wraps the string in quotes using &D, which is MATL's equivalent to MATLAB's mat2str, a function specifically made to make something that, when eval'd, will give the original matrix (or in this case, string).
The resulting 'program' is just the input string wrapped in quotes, which is thus pushed on the stack, and implicitly displayed.

Java 8, 16 bytes
A rather strange challenge, especially given that the solution is only required to support alphanumeric strings.
s->"v->\""+s+'"'

This is a lambda from a string to the string representation of a lambda taking an empty argument of any type and returning the string.

Just to note - the solution doesn't have to only support alphanumeric strings, it's just that it's only required to support alphanumeric strings.

@Quartzic Right, that's what I meant. The wording in my post was ambiguous; I've corrected it.

is it allowed to take an empty argument though?

Yep, that's the consensus on the meta site. The interpretation we Java golfers have been using is that a single empty input may be added only if there are no other inputs and the empty input is unused.

Batch, 14 bytes
@echo @echo(%*

Works for special characters too if they are quoted using "s rather than ^.

Perhaps @echo.@echo.%* would be more correct? The input could be potentially empty.

@ConorO'Brien Well I don't need the first . because that's never empty, and I used a ( for the second case because that's more reliable than ., but thanks for the suggestions anyway!

np! I just like the symmetry between the @echo.s lol

eacal, 38 bytes
strap string put string
put strap arg

Try it online!
Simply appends the string put string to the memory string, then appends the argument, which is printed.

Ly, 14 bytes
"\""&i"\"&o"&o

Try it online!
Explanation
"\""&i"\"&o"&o

"\""           # push `"`
    &i         # take input
      "\"&o"   # push `"&o`
            &o # output stack
               # test -> "test"&o
               # "test"&o = push "test" and output stack

Bash, 10 bytes
Saved 2 bytes thanks to @manatwork!
echo{,} $1

Try it online!

R (+ pryr), 27 25 bytes
pryr::f(function()cat(x))

which evaluates to the function:
function (x)
function() cat(x)

which returns the function:
function()cat(x)

where x is defined in the scope of the first function, and taken directly from its input.

If I try this, I get:
f=pryr::f(function()print(x))
f('test')
function()print(x) <environment: 0x000000000aad19d8>
I'm not sure I can actually then run that output code and get the string 'test'. Obviously this answer outputs a function that prints the string, I'm just not sure how literally to interpret the spec.

@BLT I am not sure what exactly your objection is. The returned function will print whatever was passed into x.

I guess it's more a question than an objection. The spec is "outputs a piece of code ... that, when run, will output the initial input string." Literally taken, that means I need to be able to run function()cat(x) and get the string, but that's not literally true - I'd have to save that function, and x would have to be saved somewhere ... does this mean that the spec isn't actually requiring "a piece of code that when run...`, and in fact is fine with returning a function that outputs the string?

I'm just getting hung up by the fact that if I run function()cat(x) then it won't actually return x - I have to actually invoke the function with x as input. Am I misunderstanding? Being overly literal?

@BLT I understand. I just assumed the standard definition of full program/function. I'll ask to clarify.

Carrot, 1 byte
#

How it works
# //Takes the input and places it onto the string stack
  //This is then output implicitly

{input} //The next program then consists of the input string
        //This is then placed directly onto the string stack
        //Then output implicitly

An alternative, also at 1 byte is:
$

This works the same as the above but only takes the first line of input. Seeing as input will only ever be [A-Za-z0-9] this is fine.

Considering the spec only claims that you need to handle A-Z, a-z, and 0-9, isn't this competing?

@jkelm I must have missed that part, then yes this is competing.

Would this work for input 01?

@quartata I believe so, it’s been a while since I’ve used Carrot though.

QBasic, 25 23 bytes
INPUT s$
?"?";
WRITE s$

Gets input from the user, and then prints a question mark followed by the input wrapped in double quotes. (Question mark is a shortcut for PRINT.)

><>, 29 bytes
/->:?v";"o;
/l^  >"o''"o{ooo1

Takes input using the -s flag
Prints a program that reads and print the original input character by character.
input -> 'i'o'n'o'p'o'u'o't'o;

Lua, 31 bytes
print('print([['..(...)..']])')

Try it online!

AWK, 25 bytes
$0="BEGIN{print\""$0"\"}"

Try it online!
Should work for most input other than ".
If some (possibly empty) input is allowed for the secondary program this could be shortened to:
$0="$0=\""$0"\""

dc, 10 bytes
91Pn93PACP

Try it online!
Straightforward: print an open bracket, then the input, then the close bracket and the letter p for the print command. 91Pn23920P also works.

Julia 0.6, 8 bytes
s->()->s

Try it online!
Function that takes a string, and returns a closure that returns the string when called.
Alternately, a program outputting a program:
Julia 0.6, 28 26 bytes
print(:(show($(ARGS[1]))))

Try it online!
(Removed, of all things, a trailing whitespace. Smh. Also changed inner print to show.)

R, 41 37 characters
function(x)"[[<-"(sys.call(),1,"cat")

How it works:
sys.call (makes only sense if used from within a function) returns the call; the first element of it is the name of the function; this is replaced on-the-fly by cat (which will print its arguments).
A nicer version:
sqk <- function(x)"[[<-"(sys.call(),1,as.name("cat"))
# will print cat(args) instead of "cat"(args) - both are functional but the 2nd is nicer

Example with output:
> sqk("The paws")
cat("The paws")

05AB1E, 0 bytes

Try it online! Takes input surrounded in any of "‘’“” (as long as the first and last quotes are the same).
Explanation
The program immediately reaches the end, so it triggers implicit output. Since the length of the stack (0) is less than the arity of the print function (1), it implicitly checks if there's input (which there is), and if so uses it as the argument. It outputs with a trailing newline, but that doesn't matter since newlines are nops in 05AB1E.
TL;DR: The null program in 05AB1E is a one-line cat.
Finally, each of "‘’“” are used for strings. The difference is that ‘’“” are used for compressed strings while " is regular. However, ‘’“” treat all ASCII characters normally, so they don't make a difference for this challenge. Declaring strings pushes them to the stack, so now the original input is on the stack of the generated program. At the end, it implicitly outputs the top of the stack - which is, you guessed it, the original input.
Example
Say you input "testing123". Since the program is a one-line cat, it outputs "testing123". Running this will push everything between "" to the stack, therefore pushing the string "testing123". Finally, it implicitly outputs the top of the stack, printing testing123.

naz, 110 bytes
2x0v1x1f1r3x0v4e2x1v2f0x1x2f1v3x0v3e1s2x1v0m1a1o8m4m3m1a1o2f0x1x3f0m1a1o8m3m5m9s1o2d7s1o3d7m3s1o1f0x1x4f0a0x1f

Works for any null-terminated input string, with some caveats: programs generated for strings containing any control characters between SOH and TAB (values 1-9) will produce incorrect output due to a language quirk, and programs generated for strings containing any control characters between VT and US (values 11-31), or the control character DEL (value 127), will error out with invalid output value if run. Luckily, none of these cases are required by the challenge.
Output programs are generated naïvely and are thus near-irreducible; the output program for an input of ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 will take around 125 milliseconds to generate, but around 10 seconds to run.
Explanation (with 0x commands removed)
2x0v                                 # Set variable 0 equal to 0
1x1f                                 # Function 1
    1r                               # Read a byte of input
      3x0v4e                         # Goto function 4 if it equals variable 0
            2x1v                     # Otherwise, store it in variable 1,
                2f                   # and call function 2
1x2f                                 # Function 2
    1v                               # Set the register equal to the value of variable 1
      3x0v3e                         # Goto function 3 if this equals variable 0
            1s2x1v                   # Otherwise, subtract 1 from variable 1,
                  0m1a1o8m4m3m1a1o   # output "1a",
                                  2f # and jump back to the start of function 2
1x3f                                 # Function 3
    0m1a1o8m3m5m9s1o2d7s1o3d7m3s1o   # Output "1o0m"
                                  1f # Call function 1
1x4f                                 # Function 4
    0a                               # Add 0 to the register
1f                                   # Call function 1

APL (Dyalog Unicode), 12 bytes
∊'⍞←'''⍞''''

Outputs programs as ⍞←'input'
Try it online!

Vyxal, 1 byte
q

Try it Online!
Note Vyxal uses backticks for strings, not the usual quotes.

This isn't actually valid, as vyxal uses backticks for strings. However, this answer can simply be q because there's a built in for quoting strings

oh so sorry @lyxal Thanks for the tip!

Common Lisp, 13 bytes
`,(read-line)

Try it online!
For instance, given the input john, the output will be "john", which evaluates to itself.
For a program that works through printing and not through the REPL:
Common Lisp, 20 bytes
`(princ,(read-line))

that produces (princ input-string).

><>, 37 bytes
i:1+?!v
-1"#"~<.1fo;!?l"<.09o;!?l"r}:

Try it online!
Fairly simple;
Takes input, prints out a printing loop with the string attached to the end.

CJam, 2 bytes
q`

Explanation:
q  e# Input
`  e# String representation

1 byte by removing the ``` and taking input surrounded in quotes.

Swift, 47 bytes
print("print(\"\(CommandLine.arguments[1])\")")

I think this is pretty straight forward.

Proton, 15 bytes
'print(%r)'&(%)

Try it online!
Binds 'print(%r)' to the left argument of % string formatting. When the input is given, it is applied as the second (right) argument which formats into the print statement.

Pyth, 3 bytes
+Nz

Try it online!
Explaination:
+Nz   expects any input
+     joins on same line
 N    quotation mark
  z   input as string

Lua, 30 bytes
print("print(\"".. ....."\")")

Try it online!

you can replace the " with ' to allow you to change the "s to "s or you could change the " to 's to get 28 bytes

Mathematica, 15 bytes
"\""<>#<>"\"&"&

Not much.

05AB1E, 3 bytes
'"«

Try it online!

Surround input with quotes.
-1 @Adnan.

This doesn't work, putting a quote mark after text doesn't interpret that text as a string... maybe you were looking for ì (prepend), since you want a quote at the start of the text, not the end. Also, per meta consensus you're allowed to take input surrounded in quotes, making a 0 byter possible. ;)

Mathematica, 14 bytes
Defer@Print@#&

For input "test", this function will output Print["test"], which prints "test" when run.

Rexx (Regina), 14 bytes
say say arg(1)

Try it online!

C++, 125 bytes
Warning : the code that will be printed will be invalid if input contains at least one of the character "
#include<iostream>
int main(int a,char**v){std::cout<<"#include<iostream>\nint main(){std::cout<<\""<<(a>1?v[1]:"")<<"\";}";}

C++, 116 bytes, undefined behavior if nothing is passed as console argument
If empty strings are considered as invalid input :
#include<iostream>
int main(int a,char**v){std::cout<<"#include<iostream>\nint main(){std::cout<<\""<<v[1]<<"\";}";}

Technically, for an empty string as input you'd have to do ./program "", so the second program is equally valid.

Retina, 5 bytes
\`^
¶

Try it online!
For an input like testing123 returns the program:

testing123

which in turn produces the desired output.
Try it online!
There might be a trick to disable the newline append with shorter syntax, but I don't know it!

C#, 16 bytes
s=>$"()=>\"{s}\""

Befunge-98 (PyFunge), 30 bytes
'":v
~\#[
<v">:#,_""#
<>4k,'@,

Try it online!
This prints a program in the form "...ihgfedcba">:#,_@, which prints abcdefghi...
Explanation
The code boils down to:
'":v    Push 2 quotation marks

~\#[    Get input and swap the top 2 items until EOF.
            Because every time we put a new value from input on the stack we also swap,
            the second quotation mark will float to the top, surrounding the input.

   >:#,_       A standard "print until the top is 0" loop
        ""#    Pushes a space, which is fine, since we control how much we print later
<v">:#,_"      When the IP gets reversed, we actually push the loop backwards onto
               the stack. This lets us print it later, instead of having to hardcode it.

 >4k,'@,       Prints 5 characters, being the printing loop from before, along with a @
<     @,       Prints an extra space, but it doesn't matter, and ends the program

J, 12 bytes
'echo',quote

Try it online!

Ruby -n, 12 bytes
$><<"p'#$_'"

Try it online!

Aceto, 14 13 11 bytes
'"drsJJp'pp

Try it online!

'"       push a quote character
  d       duplicate
   r       get input
    s       swap top stack items, so the input is between the two quotes
     JJ      Join top two items, 2x
       p  p    print
        'p      push literal:p

Javascript, 20 bytes
Uses eval to make a new function from the input string.
a=>eval(`a=>'${a}'`)

Julia 0.6, 18 bytes
x->"print(\"$x\")"

Try it online!

JavaScript Firefox, 6 bytes
uneval

WinDbg, 14 bytes
.echo.echo $u0

Input is taken by setting the fixed name alias $u0 (so that input can be either a string or number).
Running this will print:
.echo {value_of_$u0}

Which when executed prints the input.
Example:
$$ set input
r$.u0=testing123

$$ run code
.echo.echo $u0
$$output: .echo testing123

$$ run output
.echo testing123
$$output: testing123

How it works:
.echo            $$ print the rest of the statement
     .echo       $$ part of the string that gets printed
           $u0   $$ automatically expands to the value of the fixed name alias,
                 $$ the expanded alias is printed
                 $$ because only a-zA-Z0-9 needs to be handled, no special logic around the
                 $$ alias expansion with regard to spaces, ", or ; interfering with the
                 $$ next .echo needs to be done

How the output works:
.echo            $$ print the rest of the statement
      {string}   $$ the string that gets printed, guaranteed to be one statement because
                 $$ it can't contain ; or " and can't start with a space

T-SQL, 28 bytes
SELECT'PRINT'''+s+''''FROM t

An input table is allowed per our IO rules, so I simply create a PRINT statement with the appropriate quotation marks.
An input of FooBarBaz109481 in the input table t will result in the following output:
PRINT'FooBarBaz109481'

Which will output the original string.
The original question says the string will only contain alphanumerics, so we won't have to handle any quote marks in the input itself.

JavaScript (Node.js), 49 bytes
console.log('console.log("'+process.argv[2]+'")')

Try it online!
Takes input through argv[2], the first argument in TIO (May be different depending on where it is tested), and prints in the  console.log("YOUR_MESSAGE") format. Requires a string without quotes (unless escaped with \) with available characters A-Z, a-z, and 0-9.
Explanation
console.log(           // Log the output (open the outer log statement)
  'console.log("'      // Take console.log with opening parenthesis and quote
    + process.argv[2]  // Add the command-line argument after the quote (the input)
    + '")'             // Add the closing quote and parenthesis
)                      // Close the outer log statement

R, 5 4 1 0 bytes
Thanks to JayCe for contributing the one-byte answer!
There are a number of short R programs that would ...

take a string as input, and output a piece of code in the same
  language that, when run, will output the initial input string

. Some of these are listed below, one on each row, in descending order of length:
identity     # 8 bytes
force        # 5 bytes
print
eval         # 4 bytes
c            # 1 byte
             # 0 bytes

This is inspired by NoOneIsHere's 1-byte answer in Pyth which is said to "just evaluate the input". This is exactly what force and identity do. eval and c achieve the same result in different ways. But why stop here? When you feed a string into R, it will be evaluated (to itself) and printed in quotes. A quoted string is a valid R program. That's the idea of the 0-byte answer.
Uniquely, the same program works identically in R and Python:
R way
> "yo ho ho and a bottle of rum"
[1] "yo ho ho and a bottle of rum"

Python way
>>> 'yo ho ho and a bottle of rum'
'yo ho ho and a bottle of rum'

Funny I had not seen your answers before posting mine. If way is valid there is a function way shorter than eval that does the job... it’s actually just one byte... c

Or zero bytes using REPL?

The question is really what “output” means... If it means “printing” then this answer is not valid.

R, 34 bytes
cat("cat(",scan(,""),")",sep="\"")

Try it online!
Non-functional answer - longer than the functional one

Excel VBA, 10 bytes
An anonymous function that outputs an anonymous function that prints the value of cell A1.
?"?"""[A1]

Example I/O
Given that cell [A1] that is populated with One
?"?"""[A1]
?"One
One

Yabasic, 22 bytes

An anonymous function that takes input, S$ as a string and outputs a function that outputs S$ to the console.
This relies on the fact that the Input Call will print a ? character to the console as a prompt when no explicit prompt is provided
Input S$
?"\""+S$+"\""

Try it online!

Lua, 29 bytes
print('print("'.. ... ..'")')

Try it online!

wat O_o what even is .. ... ..

.. = [Concatenate] ... = Argument .. = [Concatenate again]

Scala, 79 bytes
println(s"""object x{def main(a:Array[String])=println("${args.mkString}")}""")

Try it online!

you shouldn't use that as argument since it doesn't work

@ASCII-only I didn't get it, can you help me explain a more bit?

"asdf",10 doesn't work, 2. you don't have to support that. so just change it to letters and numbers only

@ASCII-only Thanks :-)

oh. also you have to return a valid submission, i.e. a function or program (also your submission also has to be valid. so you'd need your header and footer inside your post body as well here

@ASCII-only, So you meant I should print the whole program?

Let us continue this discussion in chat.

Perl 5 -p, 12 bytes
$_="say'$_'"

Try it online!

Rust, 26 bytes
Input needs to be enclosed in double quotes: ""
|a|print!("||print!({a})")

Playground

Thunno 2, 1 byte
Ṙ

Attempt This Online!
Built-in for "repr" (Thunno 2 has implicit input). Essentially this surrounds the string with double quotes. So, when you run the program a string gets pushed to the stack and gets implicitly output.


text:
Reliably Broken Sort
Given a list of positive integers that contains at least 3 distinct entries, output a permutation of that list that isn't sorted in ascending or descending order.
Examples
1,2,3 -> 2,1,3 or 3,1,2 or 1,3,2 or 2,3,1
1,2,3,3 -> 2,1,3,3 or 3,1,2,3 or 1,3,2,3 etc..

Thanks @Arnauld and @NoOneIsHere for the title!

Will the input always be sorted?

Must the sort be "reliable" in that given a given set of entries, it always produces the same permutation as output?  Or must it only be "reliable" in that the output is not sorted?

It must just satisfy the specs.

Would a nested array be allowed as output? e.g., [2,[1,3]].

No, it should be one single array/list.

JavaScript (ES6), 39 34 bytes
a=>[a.sort((x,y)=>x-y).pop(),...a]

Sort the array in ascending order, pop the last element and use it as the first element of a new array. Then destructure the remaining elements of the original array into the new array (In JS, both sort and pop modify the original array).

Test it

o.innerText=(f=

a=>[a.sort((x,y)=>x-y).pop(),...a]

)(i.value=[1,2,3]);oninput=_=>o.innerText=f(i.value.split`,`)
<input id=i><pre id=o>

Why cant you just do a.sort()?

@geokavel: Because JS's sort method sorts lexicographically.

So because it's already unreliably broken? =D

Brachylog, 2 bytes
o↻

Try it online!
or
o↺

Try it online!
Sorts then rotates the list

Jelly, 3 bytes
Ṣṙ1

Try it online!

Ṣṙ- also works (just felt like saying that; you probably knew :P)

@HyperNeutrino Yep that works too, same bytecount :p

In which encoding is Ṣṙ1 only three bytes? In UTF-8, it's 7 bytes.

@heinrich5991 Jelly uses a custom codepage.

I feel like everyone who uses Jelly must have a browser extension which adds a button to automatically post the "Jelly uses a custom codepage" comment.

Ohm, 2 bytes
S╙

Try it online!
Sort and rotate to the right.

Japt, 3 bytes
n é

Test it
Sorts (n) the array and rotates it (é) one element to the right.

APL, 9 bytes
{1⌽⍵[⍋⍵]}

Try it online!
How?
⍵[⍋⍵] - sort the list
1⌽ - rotate by 1

Also works in GNU and ngn!

@Zacharý guess I'll just remove the dyalog...

Python 3, 31 bytes
lambda a:sorted(a)[1:]+[min(a)]

Try it online!
-1 byte thanks to xnor

...How did I not see this basic logic. >.>

@totallyhuman lol all 3 of my answers do the exact same thing. but ha :P Also I merged your PR for iOS -> MacOS :P

Yeah, I noticed and deleted my branch. :P

Putting the min at the end saves a byte.

Pyth, 7 5 4 bytes
.P1S

Try it online!
-1 byte thanks to FryAmTheEggman

You can save a byte by using permutations: https://pyth.herokuapp.com/?code=.P1S&input=%5B314%2C+112%2C+938%2C+792%2C+309%2C+308%5D&debug=0

@FryAmTheEggman thanks, I'll update it when I get to a computer.

TI-Basic (TI-84 Plus CE), 31 bytes
Prompt A
SortA(LA
max(LA→B
dim(LA)-1→dim(LA
augment({B},LA

Prompts for input in the format {1,2,3,4}.
TI-Basic is a tokenized language, all tokens used here are one-byte.
Explanation:
Prompt A         # 3 bytes, store user input in LA
SortA(LA         # 4 bytes, sort LA ascending
max(LA→B         # 6 bytes, save the last value in the sorted list to B
dim(LA)-1→dim(LA # 11 bytes, remove the last value from LA
augment({B},LA   # 7 bytes, prepend B to LA and implicitly print the result

05AB1E, 2 bytes
{Á

Try it online!

05AB1E, 2 bytes
{À

Try it online!

Ninja'd (almost) :P

Haskell, 36 37 bytes
import Data.List
f(a:b)=b++[a];f.sort

Use view patterns to match on the head of a sorted version of the input list, then append the first item of the list to the tail of the remaining list.
View patterns aren't worth it. Sort the list, take the head off, append it to the end. In this case, it turns out that the naive solution typed out compactly is the best.

Welcome to PPCG! Great idea to use view patterns, I didn't know about them before. Unfortunately, they are not enabled in standard Haskell, so per site rules you need to include the bytes for the command line flag -XViewPatterns. Counting those the standard way f(a:b)=b++[a];f.sort is shorter.

I somehow wasn't thinking about the flag needed. I guess I use them so much that I forgot that I turn it on in my Cabal files and that it's not part of the language.

Retina, 21 bytes
O#`
s`(.*)¶(.*)
$2¶$1

Try it online! Sort and rotate as per usual. At least there's no unary conversion this time.

Java 8, 68 37 bytes
l->{l.sort(null);l.add(l.remove(0));}

-31 bytes thanks to @Nevay (forgot Java 8 had a List#sort(Comparator) method..)
Modifies the input-ArrayList, instead of returning a new one.
Explanation:
Try it here.
l->{                   // Method with ArrayList parameter and no return-type
  l.sort(null);        //  Sort the input-list (no need for a Comparator, thus null)
  l.add(l.remove(0));  //  Remove the first element, and add it last
}                      // End of method

You can use l->{l.sort(null);java.util.Collections.rotate(l,1);} to save 16 bytes.

Alternatively you can use l->{l.sort(null);l.add(l.remove(0));} to save 31 bytes (requires the usage of a not fixed sized list).

@Nevay nice one, but... the parentheses are a bit off in regards to the documentation: the reality is that the optional operations add and remove must be implemented; nothing is said about fixed-sized list... Kevin Cruijssen, given that there are much better alternatives in the previous comments, I'll wait for an edit before +1ing.

R, 33 32 29 bytes
Takes input from stdin. Sorts the list and then moves the first element to the end, ensuring that it is no longer sorted. Saved three bytes due to Giuseppe.
c(sort(x<-scan())[-1],min(x))

Another implementation, same byte count:
c((x<-sort(scan()))[-1],x[1])

c(sort(x<-scan())[-1],min(x)) is 29 bytes using essentially the same idea as yours.

Perl 6,  43  19 bytes
{first {![<=]($_)&&![>=] $_},.permutations}

Try it
*.sort[1..*,0].flat

Try it
Note that [1..*,0] would result in ((2,3),1), so .flat is there to turn it into (2,3,1)

Mathematica, 18 bytes
RotateLeft@Sort@#&

Try it online!

Shorter: RotateLeft@*Sort

Ly, 7 bytes
&nasprl

Try it online!
Ugh, ruining the sort is so expensive!
Explanation:
&nasprl

&n      # take input as a list of numbers
  a     # sort
   sp   # save top of stack and pop
     r  # reverse stack
      l # load saved item

PHP, 44 bytes
requires PHP 5.4 or later for short array syntax.
sort($a=&$argv);print_r([array_pop($a)]+$a);

sort arguments, replace 0-th argument with removed last argument, print.
Run with -nr or try it online.

The 0-th argument is the script file name, "-" if you call PHP with -r. "-" is compared to the other arguments as a string, and since ord("-")==45, it is smaller than any number. The numbers themselves, although strings, are compared as numbers: "12" > "2".
php -nr '<code>' 3 4 2 5 1 and sort($a=&$argv) lead to $a=["-","1","2","3","4","5"] →
[array_pop($a)]+$a is [0=>"5"]+[0=>"-",1=>"1",2=>"2",3=>"3",4=>"4"],
which results in [0=>"5",1=>"1",2=>"2",3=>"3",4=>"4"].

Can you explain why [array_pop($a)]+$a doesn't overwrite the 0th index of $a? For example: $a=[1,2,3,4,5], array_pop($a) = 5, $a=[1,2,3,4]. If you do [5]+[1,2,3,4], shouldn't it end up being [5,2,3,4] because both arrays have a 0th index?
I'm confused because the PHP manual says "The + operator returns the right-hand array appended to the left-hand array; for keys that exist in both arrays, the elements from the left-hand array will be used, and the matching elements from the right-hand array will be ignored."

@jstnthms The + operator does not append, it merges (without reordering the indexes; but that doesn´t matter here). The important point is that $a points to $argv and $argv[0] contains the script´s file name, the arguments start at index 1. I extended the description. Thanks for the question.

Pyth, 5 bytes
.>SQ1

Explanation
SQ - sort input list
.>SQ1 - rotate input list cyclicaly by 1

Retina, 10 bytes
O#`
O^#-2`

Try it online!
O#`     Sort the list
O^#-2`  Reverse sort the list other than the last element

This leaves the list with the 2nd highest element first and the highest element last which is never correctly sorted

Gaia, 3 bytes
ȯ1«

Try it online!
Same as other answers: sort ȯ and rotate left once 1«.

Ruby, 18 bytes
Submitted on mobile. Please don't kill me for problems.
->a{a.sort.rotate}

Python 3, 28 bytes
lambda a:a[1:a.sort()]+a[:1]

Try it online!
a.sort() sorts a in place and returns None. None can be used as a slicing index and is the same as omitting that index.

Python 3, 31 bytes
lambda a:a.sort()or[a.pop(),*a]

Try it online! or Verify all test cases.
Inspired by Shaggy's JS answer.

RProgN 2, 2 bytes
§›

Try it online!

Julia, 23 bytes
f(x)=sort(x)[[2:end;1]]

Slightly shorter than, but equivalent to f(x)=circshift(sort(x),1).
I wish I could makeamethod based on select that was more, compact but I can not

Common Lisp, 52 bytes
(let((x(sort(read)'<)))(rotatef(nth 0 x)(nth 1 x))x)

Try it online!

Clojure, 36 bytes
#(let[s %](cons(last s)(butlast s)))

Stole the solution to sort it and push the last element to the start of the list.

TeX - 207 183 bytes
\def\a#1 #2 #3 #4 {\ifnum#2#1#3\def\e{#3 #4 #2 }\else\def\e{#2 #4 #3 }\fi\e}\def\b#1 #2 #3 {\a< #1 #2 \a> #3 {} }\def\c#1 #2 {\ifnum#1=#2\let\b\f\def\d#1 {#1 \c}\else\let\d\b\fi\d#1 #2 }\def\f#1 #2 {#2 #1 }

This is the best I can do with a language that doesn't really have data structures, or many builtins.
The approach is to take the first three numbers we find, and do a broken sort as follows: Sort the first two by greater, and then take the second two by lesser. This should always result in our list being unsorted. It's convenient to ignore anything  but the first 3 unique inputs.
We also have a check for two of the same number in a row. In that case, we scan ahead until we find a different number, and then switch the two, ensuring that our list is out of order.
I'm gonna work on golfing this down, but it's the best approach I can think of.
EDIT: Considerable work has been put in to this, to make it more golfy and also actually work. So here it is:
\let~\def~\a#1 #2 {\if^#2~\e{\box9 #1 }\else\ifnum#1\h#2~\e{\hbox{#1 }\a#2 }\else~\e{\hbox{#2 }\a#1 }\ifnum#1=#2~\h{=}\setbox9=\lastbox\fi\fi\fi~\g{>}\e}~\g{<}~\h{\g}\everypar{\a}\x^

I changed the the method from inserting things into the input to one where we recurse, replaced \expandafter with \everypar, and added that when it finds an equal number, it grabs the last number typeset and saves it until the second to last slot, ensuring that 1 2 2 (the case that secretly broke the previous answer) will be incorrectly sorted as 2 1 2.
This is just a function, to properly use it you need to: have input stored on the variable \x (or you could type in a list of numbers, with a ^ as a delimeter).
If you'd really like to try this, then do this
\read1to\x

before the lines of this function.

Proton, 19 bytes
a=>sorted(a)[1to,0]

Try it online!
-2 bytes indirectly thanks to xnor
Not yet working on TIO; waiting for a pull.

Ohm, 2 bytes
S╜

Try it online!
I think this is dissimilar enough from totallyhuman's post to post a new answer; I hope you don't mind :P EDIT: DAMMIT YOU NINJA'D ME

Ninja'd you. ;)

Python, 31 bytes
def f(a):a[1:]=a[a.sort():0:-1]

Yet another Python solution.
Sadly, this one has the same length to HyperNeutrino's answer.

C# (Mono), 76 67 bytes
using System.Linq;a=>a.OrderBy(n=>n).Skip(1).Concat(new[]{a.Min()})

Saved 9 bytes thanks to @Patrick Stephansen.
Try it online!

Save a few bytes: a=>a.OrderBy(n=>n).Skip(1).Concat(new[]{a.Min()})

Thunno 2, 2 bytes
ṠỤ

Try it online! Sort and rotate left.
ṠṾ

Try it online! Sort and rotate right.

Ruby, 20 bytes
->(x){x.sort.rotate}

I can't figure out how to use lambdas on TIO, but I'll add a link when I do

SmileBASIC, 33 bytes
DEF B A
SORT A
PUSH A,SHIFT(A)END

Modifies the array in place. This uses the simple sort+rotate algorithm, though there may be a shorter solution involving RINGCOPY or something (the problem being that COPY and RINGCOPY don't work well when copying between overlapping parts of the same array)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Fractal Cathedral
Given a positive integer n >= 1, output the first n rows of the following structure:
   #
  # #
  ###
 #   #
 # # #
 ## ##
 #####
#     #
#  #  #
# # # #
# ### #
##   ##
## # ##
### ###
#######

The n-th 1-indexed row is the binary representation of n, mirrored without copying the last character, with # in place of 1 and <space> in place of 0. All rows are centered.
You must output as ASCII-art but you may use any non-whitespace character in place of where I use # in the example. Trailing whitespace is allowed, and a trailing newline is allowed. The output must look like the example, and no extra leading whitespace or leading newlines.
You can view the first 1023 rows of the fractal cathedral here.
To generate larger test cases, here's an ungolfed reference implementation in Python

Nice idea.  I wouldn't have guessed binary numbers to have produced such pretty ascii art.

@Jonah Thanks :) Glad you like it

Both links are pointing to the generated cathedral.

@Otávio :I will fix, thanks

MATL, 10 bytes
:B2&Zv35*c

Try it online!
Explanation
:      % Implicitly input n. Push range [1 2 ... n]
B      % Convert to binary. Gives a matrix where each row corresponds to
       % a number. Rows have left-padding zeros if needed
2      % Push 2
&Zv    % Symmetrize along sepecified dimension (2nd means horizontally),
       % without repeating the last element
35*    % Multiply by 35 (ASCII code for '#')
c      % Convert to char. Char 0 is shown as space. Implicitly display

I wonder if it would be helpful to add some sort of builtin that corresponds to multiplying by 35 then converting to char. It seems to be used often

@ConorO'Brien It is used often, yes. But it would be a two-char built-in, so there would be no gain

No gain? 35*c is 4 characters

@ConorO'Brien Ah, you mean with 35 fixed? That seems a little specific. On the other hand, some challenges allow any char, so it may be a good idea. Do you think # is the most common?

For reference, this feature has been implemented (function Zc, with character 35, i.e. #). Thanks, @ConorO'Brien!

05AB1E, 9 bytes
Code:
Lb€û.c0ð:

Uses the 05AB1E encoding. Try it online!
Explanation:
L              # List [1, .., input]
 b             # Convert each to binary
  €û           # Palindromize each binary number
    .c         # Join the array by newlines and centralize
      0ð:      # Replace zeroes by spaces

Jelly, 12 bytes
RBUz0ZUŒBo⁶Y

Try it online!

I also have to go, so I will read comments when I get back. Feel free to out-golf me.

+1 for "feel free to outgolf me" and for the good answer.

JavaScript (ES6), 106 bytes
Uses 1 as the non-whitespace character.
f=(n,k=0)=>k++<n?[...Array(32-Math.clz32(n))].reduce((s,_,i)=>(c=k>>i&1||' ')+s+(i?c:''),'')+`
`+f(n,k):''

Demo

f=(n,k=0)=>k++<n?[...Array(32-Math.clz32(n))].reduce((s,_,i)=>(c=k>>i&1||' ')+s+(i?c:''),'')+`
`+f(n,k):''

O.innerText = f(15)
<pre id=O>

Alternate version (same size)
Without Math.clz32():
f=(n,a=[k=i=0])=>n>>i+1?f(n,a,a[++i]=i):k++<n?a.reduce((s,i)=>(c=k>>i&1||' ')+s+(i?c:''),'')+`
`+f(n,a):''

Very nice! First time I've seen Math.clz32 - I didn't even know it existed!

@Birjolaxew Yup, this is an ES6 addition. It comes handy every once in a while.

Husk, 21 20 18 bytes
Thanks @Zgarb for golfing off 2 bytes!
S↑(tfS=↔ΠR" #"←DLḋ

Try it online!
Ungolfed/Explanation
To avoid lengthy padding, this determines the width of the fractal which is given as 2*len(bin(N))-1 and generates all sequences of that length with the symbols #,_ ('_' denotes a space).
Since the Cartesian power is generated in order and the binary numbers are too, this is fine. All we need to do to get the fractal at this point, is filtering out all palindromes and that's basically it:
                    -- implicit input N
S↑(                 -- take N from the following list
        ΠR" #"      --   Cartesian power of [" #"] to
                Lḋ  --     number of bits in bin(N)
               D    --     2*
              ←     --     -1
    fS=↔            --   filter out palindromes
   t                --   drop the first line (all spaces)

Ṙ; can be just R, and ȯ is unnecessary. Nice answer idea!

Python 2, 92 bytes
n=input()
for x in range(n):s=bin(2**len(bin(n))/4+x+1)[3:].replace(*'0 ');print s+s[-2::-1]

Try it online!
In Python 3, s=f'{x+1:0{len(bin(n))-2}b}'.replace(*'0 ') is shorter, but int(input()) and parens around the print argument push it up to 95 bytes.

That's a copy of mine :) (but clever use of 2**len(bin(n))/4 anyways)

C# (.NET Core), 192 178 bytes 168+23

thank you TheLethalCoder for the help.
x=>new int[x].Select((_,z)=>Convert.ToString(z+1,2).PadLeft((int)Math.Log(x,2)+2).Replace('0',' ')).Aggregate((y,z)=>y+"\n"+z+new string(z.Reverse().Skip(1).ToArray()))

Try it online!
pretty sure this can be reduced by a lot, most likely in the padding and reversing of the string.

Welcome to PPCG! At the moment this answer is just a code snippet. It can be fixed by adding the x=> into the byte count and note you don't need to include the trailing semi-colon. Enumerable.Range(1,x).Select(z is shorter as new int[x].Select((_,z) (I think that's correct). As you are using Linq you should include using System.Linq; into your byte count. You are also using Math so you should include using System; or fully qualify it. Note that this is then shorter as namespace System.Linq{}

You don't need to include ,' ' in the PadLeft call as a space is the default.

168 bytes + 23 for namespace System.Linq{}

@TheLethalCoder sorry for the inconvenience, it is now fixed.

No worries +1 from me it is a nice answer :)

Mathematica, 94 bytes
Column[Row/@Table[s=IntegerDigits[i,2];Join[s,Reverse@Most@s]/.{0->" ",1->"#"},{i,#}],Center]&

I really have to go, too...

Python 2, 120 118 107 bytes
thanks @luismendo, @officialaimm, @halvard-hummel
def f(l):
 for a in range(1,l+1):print(bin(a)[2:]+bin(a)[-2:1:-1]).replace(*'0 ').center(len(bin(l+1))*2-4)

Try it online!

replace(*'0 ') for 2 bytes

107 bytes

Mathematica, 98 bytes
Riffle[Nest[ArrayFlatten@{{0,#,0},{1,0,1},{1,#,1}}&,{1},⌊Log2@#⌋]~Take~#"#"/. 0->" ","
"]<>""&

Try it at the Wolfram sandbox! The ⌊ and ⌋ are three bytes each.
It's a different approach from the other answers so far, using the fractal nature of the pattern. The key step is ArrayFlatten@{{0,#,0},{1,0,1},{1,#,1}}&, which does the fractally stuff, best explained in picture form:
                 [    ]
                 [grid]
[    ]           [    ]
[grid]   --->   #      #
[    ]          #[    ]#
                #[grid]#
                #[    ]#

The code repeats this step enough times to get at least n rows, then trims off the extra rows and displays it nicely.

Gaia, 11 bytes
 #”B¦ₔṫ¦€|ṣ

Try it online!
Explanation
    ¦ₔ       For each number 1..input:
 #”B          Convert it to base 2 and use space as 0 and # as 1
      ṫ¦     Palindromize each
        €|   Centre the lines
          ṣ  Join with newlines

Python 2, 89 bytes
n=input()+1
w=' #'
while len(w)<n:w=[s+l+s for s in' #'for l in w]
print'\n'.join(w[1:n])

Try it online!

SOGL V0.12, 11 bytes
∫2─0@ŗ}¹╬⁴╚

Try it Here!

PHP, 98 97 95 94+1 bytes
while($r++<$argn)echo$s=strtr(sprintf("%".-~log($argn,2).b,$r),0," "),substr(strrev("
$s"),1);

Run as pipe with -nR or try it online. Uses 1 as non-whitespace.

sorry to spoil it, but something is wrong here. output for $argn=1 and $argn=3 is not correct, and $argn is 0-based (specified was 1-based)

@FelixPalmen fixed. The incorrectness was caused by the wrong base. Thanks for noticing.

Charcoal, 28 bytes
Ａ…·¹ＮθＷ⌈θ«Ｅθ§ #κ↓⸿ＡＥθ÷κ²θ»‖Ｏ

Try it online! Link is to verbose version of code. Explanation:
Ａ…·¹Ｎθ

Create a list of the first n natural numbers.
Ｗ⌈θ«

Repeat until all elements are zero.
Ｅθ§ #κ

Print the last binary digit of each element of the list as a  or #.
↓⸿

Move to the previous column.
ＡＥθ÷κ²θ

Divide all elements of the list by two.
»‖Ｏ

Once the left half has been drawn, reflect it.

Current versions of Charcoal have MapAssignRight(IntDivide, 2, q); which saves 3 bytes.

J, 29 bytes
' #'{~(],}.@|.)"1@(#.^:_1)@i.

Try it online!
explanation

i. integers up to n, the input
(#.^:_1) converted to base 2
(],}.@|.) row by row ("1 does that part), take the binary number (] is the identity fn), and cat it (,) with its reverse (|.), where the reverse is beheaded (}.).
' #'{~ converts the 1s and 0s to hashes and spaces.

You can use #.inv instead of #.^:_1.

@ConorO'Brien, thanks, wasn't aware of that.

Isn't this off by one? For n = 1, you print nothing. Anyways, you can shave off a few bytes with a few changes like so ' #'{~(,|.@}:)"1@#:@:>:@i. (if you're allowed to be off by one you can remove 4 more bytes). Basically, use a hook because it performs just like a fork when the left tine is ] and use the built-in #: which AFAIK is about the same as #.inv. EDIT: I figure my answer is similar enough to warrant being a comment, let me know if you think it should be an answer of its own.

@cole, thanks! i'll update it a bit later.  i thought i'd tried #: and it didn't work, but i must be remembering wrong because you're right that it does.

@Jonah you may have tried 2 #: which will only get the right-most digit. Monadic #: functions just like #.inv (or #.&:_1). This differs from dyadic #:, which only gives as many digits as there are atoms in its left argument.

@cole, indeed i think that is what i did.  thanks for the clarification.  it makes sense, after all, that anti-base is, well, anti-base.

Proton, 95 bytes
r=>{for i:range(1,r)print(((bin(i)[2to]).rjust(len(bin(r))-2)[to-1,to by-1]).replace('0',' '))}

Try it online!
There are too many bugs to not have too many brackets... I need to fix up the parser...

K (ngn/k), 19 bytes
{" #"@+a,1_|a:!x#2}

Try it online!

C (gcc), 146 108 105 bytes
#define o putchar(33-!(c&(1<<n)))
b;c;p(n){--n?o,p(n),o:o;}f(n){while(n>>++b);while(c++<n)p(b),puts("");}

Try it online!
This is a function f(n) called with the number of rows n, using an exclamation mark (!) as non-whitespace character.
Explanation:
#define o putchar(33-!(c&(1<<n)))
b;c;
p(n)
{
    // least significant bit not yet reached?
    --n?
            // print bit twice with recursive step between
            o,
            p(n),
            o
        // for least significant, just print this bit
        :o;
}

// the main "cathedral function":
f(r)
{
    // determine max number of bits to shift
    while(r>>++b);

    // iterate over rows
    while(c++<r)

        // print row recursively
        p(b),

        // newline
        puts("");
}

/**
 * footer, just calling the function
 */
main(int argc, char **argv)
{
    f(atoi(argv[1]));
}

Suggest --n&&o+p(n);o; instead of --n?o,p(n),o:o; and for(;c++<n;puts(""))p(b); instead of while(c++<n)p(b),puts("");

Perl 5, 77 + 1 (-n) = 78 bytes
$x=1+(log$_)/log 2;map{$_=sprintf"%0${x}b",$_;y/0/ /;say$_.chop.reverse}1..$_

Try it online!
Using '1' instead of '#' because it saves a couple bytes.

Python 2, 93 bytes
n=input()
for i in range(n):s=bin(2**n.bit_length()+i+1)[3:].replace(*'0 ');print s+s[-2::-1]

Try it online!

JavaScript (Node.js), 156 149 bytes
-7 bytes by @ConorO'Brien
f=(n,w=n.toString(2).length,b=n.toString(2).replace(/0/g," "),s=" ".repeat(w-b.length))=>`${--n?f(n,w)+s+b+[...b].reverse().join``.substr(1):s+"1"}
`

Try it online!
Recursive function. Unfortunately JS does not support reversing a string, so 19 bytes are used on turning it into an array and back.

You can use [...b] instead of b.split(""); you can also use .join``.substr(1) instead of .join("").substr(1); finally, I think you can use s+1 instead of s+"1"

Stax, 8 bytes
ç▼┼Ö☺Ç¬É

Run and debug it
Shortest answer so far. Uses CP437 charcode 1 in place of #.
ASCII equivalent:
{:B|pm|Cm

you need to use a non-whitespace char, which charcode 1 isn't

Japt -R, 10 bytes
õ_s*iS)êÃû

Try it
õ_s*iS)êÃû     :Implicit input of integer U
õ              :Range [1,U]
 _             :Map
  s            :  Convert to string in base
   *i          :    "*" prepended with
     S         :    Space
      )        :  End base conversion
       ê       :  Palindromise
        Ã      :End map
         û     :Centre pad each element with spaces to the length of the longest
               :Implicit output, joined with newlines

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Implement true string addition
Many languages allow strings to be "added" with +.  However this is really concatenation, a true addition would follow the group axioms:

It is closed (the addition of any two strings is always a string)

It is associative ( \$\forall a b . (a + b) + c = a + (b + c)\$)

There is an identity (\$\exists e . \forall a . a + e = a\$)

Every element has an inverse (\$\forall a . ∃b . a + b = e\$)

(concatenation violates the 4th group axiom)
So my task to you is to implement a true string addition, that is a function that takes two sequences of bytes representing strings and returns a third such that your function satisfies all the group axioms on sequences of  bytes.
It must work on all sequence of bytes representing strings including those with null bytes.
This is code-golf so answers will be scored in bytes with less bytes being better.

Python 3, 177 170 163 130 bytes
lambda a,b:s(d(a)^d(b))
def s(n,x=0,s=''):
 while n:n-=1;s+=chr(n%256);n>>=8
 return s
def d(n,c=0):
 while s(c)!=n:c+=1
 return c

Try it online!
-14 bytes thanks to notjagan
-33 bytes thanks to Leaky Nun (and switched endianness)
I have no business trying to golf anything in Python, but I didn't want to use Lua since this method needs large exact integers to work on reasonable length stings. (Note: the algorithm is still Really Slow when ramping up the string length.) This is mostly just to provide an answer ;)
Each string is self-inverse, and the empty string is the identity. This simply performs xor under a simple bijection between strings and non-negative integers. s is a helper function that computes the bijection (one way only), and d is the inverse.
Non-slow version (148 bytes, courtesy of Leaky Nun):
lambda a,b:s(d(a)^d(b))
def s(n,x=0,s=''):
 while n:n-=1;s=chr(n%256)+s;n>>=8
 return s
def d(n,c=0):
 while n:c=c*256+ord(n[0])+1;n=n[1:]
 return c

Try it online!
I'm going to hijack this for a group-theory primer as well.
Any right inverse is a left inverse: inv(a) + a = (inv(a) + a) + e = (inv(a) + a) + (inv(a) + inv(inv(a))) = inv(a) + (a + inv(a)) + inv(inv(a)) = (inv(a) + e) + inv(inv(a)) = inv(a) + inv(inv(a)) = e
This also means that a is an inverse of inv(a).
Any right identity is a left identity: e + a = (a + inv(a)) + a = a + (inv(a) + a) = a
The identity is unique, given other identity f: e = e + f = f
If a + x = a then x = e: x = e + x = (inv(a) + a) + x = inv(a) + (a + x) = inv(a) + a = e
Inverses are unique, if a + x = e then: x = e + x = (inv(a) + a) + x = inv(a) + (a + x) = inv(a) + e = inv(a)
Following the proofs should make it fairly easy to construct counterexamples for proposed solutions that don't satisfy these propositions.
Here's a more natural algorithm I implemented (but didn't golf) in Lua. Maybe it will give someone an idea.
function string_to_list(s)
  local list_val = {}
  local pow2 = 2 ^ (math.log(#s, 2) // 1) -- // 1 to round down
  local offset = 0
  list_val.p = pow2
  while pow2 > 0 do
    list_val[pow2] = 0
    if pow2 & #s ~= 0 then
      for k = 1, pow2 do
        list_val[pow2] = 256 * list_val[pow2] + s:byte(offset + k)
      end
      list_val[pow2] = list_val[pow2] + 1
      offset = offset + pow2
    end
    pow2 = pow2 // 2
  end
  return list_val
end

function list_to_string(list_val)
  local s = ""
  local pow2 = list_val.p
  while pow2 > 0 do
    if list_val[pow2] then
      local x = list_val[pow2] % (256 ^ pow2 + 1)
      if x ~= 0 then
        x = x - 1
        local part = ""
        for k = 1, pow2 do
          part = string.char(x % 256) .. part
          x = x // 256
        end
        s = s .. part
      end
    end
    pow2 = pow2 // 2
  end
  return s
end

function list_add(list_val1, list_val2)
  local result = {}
  local pow2 = math.max(list_val1.p, list_val2.p)
  result.p = pow2
  while pow2 > 0 do
    result[pow2] = (list_val1[pow2] or 0) + (list_val2[pow2] or 0)
    pow2 = pow2 // 2
  end
  return result
end

function string_add(s1, s2)
  return list_to_string(list_add(string_to_list(s1), string_to_list(s2)))
end

The idea is basically to split the string based on the power-of-two components of its length, and then treat these as fields with a missing component representing zero, and each non-missing component representing numbers from 1 up to 256^n, so 256^n+1 values total. Then these representations can be added component-wise modulo 256^n+1.
Note: This Lua implementation will have numeric overflow problems for strings of sizes greater than 7. But the set of strings of length 7 or less is closed under this addition.
Try it online!

Fun fact: Because every element is its own inverse, this group is also abelian.

Python 3.8, 93 bytes
f=lambda a,b,L=len:f(c:=a.rstrip(x:=a[-1]),x*(L(a)-L(c)^L(b)-L(d:=b.lstrip(x)))+d)if a else b

Try it online!
This doesn’t use base conversion or character codes at all. It works on strings over any alphabet \$\mathcal A\$.
We define addition by concatenation \$a + b = ab\$ except when \$a\$ ends with the same character \$\mathtt x\$ that starts \$b\$, in which case we use
$$\underbrace{\mathtt{xx\cdots x}}_{\text{$i$ times}} + \underbrace{\mathtt{xx\cdots x}}_{\text{$j$ times}} = \underbrace{\mathtt{xx\cdots x}}_{\text{$i \oplus j$ times}},$$
where \$\oplus\$ is bitwise XOR, perhaps repeatedly if \$i = j\$. For example,
$$\mathtt{uuzzzzzyxx} + \mathtt{xxyzzzv} = \mathtt{uuzzzzzzv},$$
because \$2 \oplus 2 = 0\$, \$1 \oplus 1 = 0\$, and \$5 \oplus 3 = 6\$. The identity is the empty string, and the inverse of a string is its reversal.
This describes the free product of \$|\mathcal A|\$ copies of the group \$(\mathbb N, \oplus)\$.

Jelly, 8 bytes
‘ḅ⁹^/ḃ⁹’

This uses a bijective mapping φ from byte arrays to the non-negative integers, XORs the result of applying φ to two input strings, then applies φ-1 to the result.
The empty array is the neutral element and every byte arrays is its own inverse.
Try it online!
How it works
‘ḅ⁹^/ḃ⁹’  Main link. Argument: [A, B] (pair of byte arrays)

‘         Increment all integers in A and B.
 ḅ⁹       Convert from base 256 to integer.
   ^/     XOR the resulting integers.
     ḃ⁹   Convert from integer to bijective base 256.
       ’  Subtract 1.

I was wondering which esolangs had bijective base conversion builtins...

Shouldn´t that be base 257?

@Titus No, the digits of bijective base 256 range from 1 to 256 (inclusive).

So ḅ⁹ is from bijective base 256 to integer? What does A+A give? chr(-1)?

@Titus The base-to-integer conversion process is identical for bijective and "normal" bases. [65] + [65] will yield [].

Python 2, 114 bytes
lambda a,b:s(d(a)^d(b))
d=lambda s:s and d(s[1:])*256+ord(s[0])+1or 0
s=lambda d:d and chr(~-d%256)+s(~-d/256)or''

Try it online! Works by XORing the strings interpreted as little-endian bijective base 256.

d=lambda s:s>''and-~ord(s[0])+d(s[1:])*256 saves three bytes; s=lambda d:d*'?'and chr(~-d%256)+s(~-d/256) saves one more.

@Lynn Is that second one going to work for large d?

How does this work if the strings are not of the same length?

@WheatWizard The length of the strings is irrelevant. There's a bijective mapping from the set of strings to the set of integers. The integer values are then XORed, and the mapping reversed.

@Neil Ok thanks I see now.

Python 2, 197 bytes
def n(s):
 n=s and ord(s[0])+1 or 0
 for c in s[1:]:n=n*256+ord(c)
 return(-1)**n*n/2
def f(l,r,s=""):
 i=n(l)+n(r)
 i=abs(i*2+(i<=0))
 while i>257:s=chr(i%256)+s;i/=256
 return["",chr(i-1)+s][i>0]

Try it online!
Turns the string into a number (reducing by charcode), negates if odd, then halves. Not as golfy as the other one, but faster :P

193 bytes

n is not injective, which causes problems. E.g. n("\x00\x00")==n("\xff") so this fails: print(f("\x00\x00","") == "\x00\x00")

:| oh no that's going to be so costly to fix

1 or => 1or

JavaScript (Node.js), 119 bytes
a=>b=>q(p(a)^p(b));p=x=>Buffer(x,h=0).map(c=>h=h*256-~c)|h;q=(n,i=0)=>n<2**i?i?q(n>>8,i-8)+Buffer([n]):'':q(n-2**i,i+8)

Try it online!
xor of id of string