From 11ca58ca53159c989b85f4d56c780a32ebdb66d1 Mon Sep 17 00:00:00 2001 From: lohhiiccc Date: Wed, 27 May 2026 18:19:26 +0200 Subject: [PATCH] feat: Sully.sh --- src/Sully.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Sully.sh diff --git a/src/Sully.sh b/src/Sully.sh new file mode 100644 index 0000000..79f9712 --- /dev/null +++ b/src/Sully.sh @@ -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"