It's also useful if you want to check the file into a git repo and want to keep using the diff and merge tools.
It's almost always the case that either Base32768 is denser, or encodings with 2^17 or 2^20 characters are denser.
{ base64 -d | gunzip > output; } <<EOF12345
...data...
EOF12345The reasoning being that the base64'd binary data is safe from being corrupted when the file is edited in text editors, as a response to the warning stated on the last paragraph of the original post.
It's just to mitigate the wastefulness of base64 encoding. You end up with a file that is text editor friendly and not quite as bloated as directly encoding the binary would be - but of course the file is still larger than simply appending the binary directly like in the OP.
Also, if you don't care about text editor friendlyness, you could indeed just zip the binary and then append it to the script for an even smaller file.
#!/bin/sh
sed -E '1,/^START-OF-TAR-DATA$/d' "$0" | tar xvzf -
exit
START-OF-TAR-DATA
and then run: cat extract.sh ../foobar.tar.gz > foobar.tar.gz.sh
You can then run foobar.tar.gz.sh to self-extract. And you still get the benefit of being able to modify the shell script without needing to count lines or characters without sacrificing any compression.Any reasonable person will indent a conditional exit within the block testing its condition, and more than one unconditional exit doesn't make sense.
Or add compression to reclaim at least some of the wasted space:
Also note that bash accepts line breaks in quoted strings and the base64 utility has an "ignore garbage" option that lets it skip over e.g. whitespace in its input. You can use those to break up the base64 over multiple lines: