If the currently executed script is an actually existing file, you can get the current line and extract from it the text that you want to preserve, whereas the text may be stored as a comment after a special delimiter. With envsubst
you can substitute variable expansions of exported variables. Something along:
sed -n "${BASH_LINENO}s/.*### //p" "$0" | VARIABLE="$VARIABLE" envsubst '$VARIABLE' > doc.txt ### any text; "with double quotes"; some $VARIABLE here; and 'single quotes'; and semicolons;
You could also, in the same fashion, create an eval
that would use that line content inside an eval
-ed single line generated here-document:
eval "cat <<EOF$(echo)$(sed -n "${BASH_LINENO}s/.*### //p" "$0")$(echo EOF)" > doc.txt ### any text; "with double quotes"; some $VARIABLE here; and 'single quotes'; and semicolons;
With base64 -w0
(or many other encoding) you can encode any script, also multiline, into a single line. Remove echo
from below to actually execute the script.
echo eval "$(base64 -d <<<Y2F0IDw8RU9GCmFueSB0ZXh0OyAid2l0aCBkb3VibGUgcXVvdGVzIjsgc29tZSAkVkFSSUFCTEUgaGVyZTsgYW5kICdzaW5nbGUgcXVvdGVzJzsgYW5kIHNlbWljb2xvbnM7CkVPRgo=)" > doc.txt