Skip to main content
6 of 6
deleted 26 characters in body
Jeff Schaller
  • 67.4k
  • 35
  • 116
  • 255

Delayed Expansion

I want to make a quine .sh script, and this is what I've made so far:
quine.sh:

#!/bin/sh
q="#!/bin/sh\nq=$q;echo \$q";echo $q

Focus on this line:

q="#!/bin/sh\nq=$q;echo \$q";echo $q

At the first occurence of $q (in \nq=$q), I first want to set the rest of the variable, and then this part (something line setlocal enabledelayedexpansion in batch files). Note that I want a solution for sh, not bash or something else, as I want portability. Also, do not give me tips on how to make my code shorter etc. I just want a solution for the problem above.

EKons
  • 944
  • 1
  • 8
  • 20