4 ms·
An even simpler way would be to include a marker to denote the end of the shell script, and the start of the data. For example, if you put this in extract.sh
by sudobash1 3y ago
An even simpler way would be to include a marker to denote the end of the shell script, and the start of the data. For example, if you put this in extract.sh
#!/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.
- deleted 3y ago[deleted]
- oxygen_crisis 3y agoYou've already got a marker to denote the end of the shell script baked in there, it's ^exit$
- withinboredom 3y agoThere may be more than one exit.
- oxygen_crisis 3y agoThere will be only one that is neither preceded by indentation nor followed by an exit code, so that it could match ^exit$, unless you contrive some hypothetical nonsense purely for the sake of contrarianism. Any reasonable person will indent a conditional exit within the block testing its condition, and more than one unconditional exit doesn't make sense.
- 8n4vidtmkvmk 3y agoIt would still make me uncomfortable that a 2nd exit or lack of indent would break my script. And it's less clear than an explicit marker
- withinboredom 3y agoAh fair enough. I didn’t think about using the indent, that’s pretty clever.