Created
August 30, 2011 01:44
-
-
Save has207/1179942 to your computer and use it in GitHub Desktop.
bash quine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
chr() { | |
printf \\$(printf "%03o" $1) | |
} | |
declare -a data | |
data=( | |
'#!/bin/bash' | |
'' | |
'chr() {' | |
' printf \\$(printf "%03o" $1)' | |
'}' | |
'' | |
'declare -a data' | |
'data=(' | |
'%DATA%' | |
')' | |
'' | |
'i=0' | |
'length=${#data[*]}' | |
'while test $i -lt $length; do' | |
' if test "${data[i]}" = "%DATA%"; then' | |
' j=0' | |
' while test $j -lt $length; do' | |
' echo "$(chr 39)${data[j]}$(chr 39)"' | |
' j=$[j+1]' | |
' done' | |
' else' | |
' echo "${data[i]}"' | |
' fi' | |
' i=$[i+1]' | |
'done' | |
) | |
i=0 | |
length=${#data[*]} | |
while test $i -lt $length; do | |
if test "${data[i]}" = "%DATA%"; then | |
j=0 | |
while test $j -lt $length; do | |
echo "$(chr 39)${data[j]}$(chr 39)" | |
j=$[j+1] | |
done | |
else | |
echo "${data[i]}" | |
fi | |
i=$[i+1] | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment