0

src:unix programming environment

a shell script ./bundle :it works well with text file but binary code :(

#!/bin/bash
echo '# To unbundle , sh this file'
for i
do
    echo "echo $i 1>&2"
    echo "cat >$i <<'End of $i'"
    cat $i
    echo "End of $i"
done

a simple binary file named a.out,

% ./bundle a.out >> out
% chmod u+x out
% ./out # error happened

I got:

./out: line 8: warning: here-document at line 3 delimited by end-of-file (wanted `End of a.out')

yeah, I know the `End of a.out' should be in a seprate line. But I don't know how to implemetate it.

who have some idea?

thx in advance. :D

songhir
  • 3,393
  • 3
  • 19
  • 27
  • Related: http://stackoverflow.com/questions/10491704/embed-a-executable-binary-in-a-shell-script http://stackoverflow.com/questions/18410785/bash-script-containing-binary-executable?lq=1 – Hasturkun Dec 26 '13 at 13:34
  • 1
    You could use base64 encode/decode, which is pretty standard these days... – anishsane Dec 26 '13 at 14:12
  • @anishsane yeah, a cool method to do it! thx! base64 works very well. just use base64 instead of cat in shell script. :D – songhir Dec 26 '13 at 14:19

1 Answers1

1

You can uuencode binary files (as shar does), or do as makeself does, appending the binary as is and reading it out with dd. (You could obviously also use either of these tools)

Hasturkun
  • 35,395
  • 6
  • 71
  • 104