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.