selfrep
_____

Self reproducing programs

Self reproducing programs are programs that reproduce the source they originate from, see also quine

A very simple example:

  #!/bin/bash
  # this is a self reproducing program
  cat $0

In fact, this example cheats, it is making use of the fact the the source is available, and it asks the operating system to produce a copy of that source to standard output.

On this page some examples of real self reproducing shell scripts is available, for example this one:

  #! /bin/sh
  q="'" qq='echo \#! /bin/sh;echo q=\"$q\" qq=${q}$qq$q;echo eval $qq'
  eval $qq

A nice story about self reproducing zips is here .

A comprehensive article on self reproducing programs is here .

I guess, that the mathematicians among us can read about Kleene's recursion theorem but that article is far beyond my capabilities.

In the year 2004 I played with self reproducing programs, telling my boss that that was a very important thing to do: With a self reproducing program, the changes that the source gets lost are minimized.

Here I present a recipe that can be used to convert practically any program written in practically any language into a self-reproducing program.