0

I'm trying to make self extracting file using the following Ant tasks:

...
<fixcrlf file="${src.dir}/scripts/install.sh" eol="unix"/>

<concat destfile="${build.dir}/my_program.exe" binary="yes">
    <fileset file="${src.dir}/scripts/install.sh" />
    <fileset file="${build.dir}/program.tar.gz" />
</concat>

.. and my_program.exe looks like this:

#!/bin/bash

begin=`head -30 $0 | grep -n ^START | cut -d ':' -f -1`   # find line number of the marker 
start=$(($begin+1))   # beginning of the binary archive which will be extracted                 

echo $start

...

START
#binary file starts

When I run my_program.exe I get the following error:

./my_program.exe: line 4: Binary file (standard input) matches: syntax error in expression (error token is "file (standard input) matches")
tail: +: invalid number of lines

When I run install.sh separately it finds line number just fine.

My guess is that something wrong with Ant task. Do I miss some properties that will fix it?

3
  • Is there an easy way to test my_program.exe (which is really a bash script) separately? Does it work outside of ant? I would be surprised if it did. Good Luck Commented Jun 6, 2011 at 15:06
  • I just want a number line, when you script returns <line number>:String Also, like I wrote when I run install.sh separately it finds line number fine. Commented Jun 6, 2011 at 15:12
  • Sorry, your mention of my_program.exe threw me off. The answer from bmk looks to be a good solution. Good luck! Commented Jun 6, 2011 at 15:27

1 Answer 1

4

I guess you should use the -a (resp. --text, meaning to process a binary file as if it were text) option of grep. Otherwise grep will only output "Binary file matches".

So probably the line 4 should be:

begin=`head -30 $0 | grep -na ^START | cut -d ':' -f -1`   # find line number of the marker 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.