generated from loic/c-template
feat: Sully.sh
This commit is contained in:
parent
9a66e06e08
commit
11ca58ca53
1 changed files with 43 additions and 0 deletions
43
src/Sully.sh
Normal file
43
src/Sully.sh
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -o posix
|
||||||
|
|
||||||
|
i=5
|
||||||
|
src=$'#!/usr/bin/env bash\nset -o posix\n\ni=~\nsrc=$\'@\'\n\nescape_quine() {\n\tlocal char="$1" ref="$2"\n\tcase "$char" in\n\t\t$\'\\\\\')\tprintf -v "$ref" \'%s\' \'\\\\\' ;;\n\t\t$\'\\\'\')\tprintf -v "$ref" \'%s\' "\\\'" ;;\n\t\t$\'\\t\')\tprintf -v "$ref" \'%s\' \'\\t\' ;;\n\t\t$\'\\n\')\tprintf -v "$ref" \'%s\' \'\\n\' ;;\n\t\t*)\t\tprintf -v "$ref" \'%s\' "$char" ;;\n\tesac\n}\n\nrun_quine() {\n# One comments must be present\n\toutput=\'\'\n\tfor (( k=0; k<${#src}; k++ )); do\n\t\tc="${src:k:1}"\n\t\tif [[ "$c" == $\'\\x40\' ]]; then\n\t\t\tfor (( j=0; j<${#src}; j++ )); do\n\t\t\t\tout=""\n\t\t\t\tescape_quine "${src:j:1}" out\n\t\t\t\toutput+="$out"\n\t\t\tdone\n\t\telif [[ "$c" == $\'\\x7e\' ]]; then\n\t\t\toutput+="$(( i - 1 ))"\n\t\telse\n\t\t\toutput+="$c"\n\t\tfi\n\tdone\n\tprintf \'%s\' "$output" > "Sully_$(( i - 1 )).sh"\n}\n\nif (( i - 1 < 0 )); then\n\texit 0\nfi\nrun_quine\n\nexec bash "Sully_$(( i - 1 )).sh"\n'
|
||||||
|
|
||||||
|
escape_quine() {
|
||||||
|
local char="$1" ref="$2"
|
||||||
|
case "$char" in
|
||||||
|
$'\\') printf -v "$ref" '%s' '\\' ;;
|
||||||
|
$'\'') printf -v "$ref" '%s' "\'" ;;
|
||||||
|
$'\t') printf -v "$ref" '%s' '\t' ;;
|
||||||
|
$'\n') printf -v "$ref" '%s' '\n' ;;
|
||||||
|
*) printf -v "$ref" '%s' "$char" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
run_quine() {
|
||||||
|
# One comments must be present
|
||||||
|
output=''
|
||||||
|
for (( k=0; k<${#src}; k++ )); do
|
||||||
|
c="${src:k:1}"
|
||||||
|
if [[ "$c" == $'\x40' ]]; then
|
||||||
|
for (( j=0; j<${#src}; j++ )); do
|
||||||
|
out=""
|
||||||
|
escape_quine "${src:j:1}" out
|
||||||
|
output+="$out"
|
||||||
|
done
|
||||||
|
elif [[ "$c" == $'\x7e' ]]; then
|
||||||
|
output+="$(( i - 1 ))"
|
||||||
|
else
|
||||||
|
output+="$c"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
printf '%s' "$output" > "Sully_$(( i - 1 )).sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (( i - 1 < 0 )); then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
run_quine
|
||||||
|
|
||||||
|
exec bash "Sully_$(( i - 1 )).sh"
|
||||||
Loading…
Add table
Reference in a new issue