Bash: How to extract an executable from within?

Daniel B. Thurman dant at cdkkt.com
Tue Sep 15 01:10:48 UTC 2009


On 09/14/2009 06:01 PM, inode0 wrote:
> On Mon, Sep 14, 2009 at 7:48 PM, Daniel B. Thurman <dant at cdkkt.com> wrote:
>   
>> I noticed that some (older?) shell-scripts have
>> self-extracting executables built in and extracting
>> was done done by using a tail +N $0 where N is the
>> line number where the executable line is located to
>> the end of the file. Unfortunately, Fedora's tail program
>> does not support the +N option.
>>     
> tail -n +40 should begin the tail at line 40 for example.
>
>   
>> I am looking for an alternative.
>>
>> I tried to wrap the executable with a function such as:
>>
>> outname=selfextractExe.$$
>>
>> function unWrapExe() {
>> cat <<'EOF'
>> <executable>
>> EOF
>> }
>>
>> # Do pre-shell stuff
>>
>> unWrapExe > $outname
>> ./outname
>>
>> # Do post-shell stuff
>>
>> The problem as I see it, is somehow cat blows
>> up when certain characters appear in the input
>> stream and the output executable file becomes
>> corrupted cannot be executed.  I have tried
>> echo and I cannot think of another program to
>> try.
>>
>> So, how does one go about fixing these sort of
>> problems nowadays?
>>     
> You might take a look at shar for packing executables in shell scripts.
>
> John
>
>   
OH!  So solving the main tail problem is by adding
the -n argument!  That works!

Thanks!
Dan




More information about the fedora-list mailing list