Skip to content

Instantly share code, notes, and snippets.

@has207
Created August 30, 2011 01:44
Show Gist options
  • Save has207/1179942 to your computer and use it in GitHub Desktop.
Save has207/1179942 to your computer and use it in GitHub Desktop.
bash quine
#!/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