Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have this command inside a Bash shell script, the intention of which is to apply a java command, htmlcompressor, to each HTML file found in a directory:

find $DIR -type f -name '*.html' -exec java -jar $BASEDIR/Upload/htmlcompressor-1.5.3.jar --remove-intertag-spaces {} \;

However, while the output at the command line seems to indicate that it is finding each file and doing something with it, it's not actually writing the results to the files.

According to the documentation for htmlcompressor, the usage is this:

Usage: java -jar htmlcompressor.jar [options] [input]

So there's supposed to be an input file at the named at the end, but I thought the find command took care of that. Seems I'm wrong about that, though.

What can I do to make it actually act on the files I find?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

What you've provided seems to be correct; you can verify that java is being invoked correctly by inserting echo into the command:

find $DIR -type f -name '*.html' -exec echo java -jar $BASEDIR/Upload/htmlcompressor-1.5.3.jar --remove-intertag-spaces {} \;

(assuming a properly POSIX compliant system which has non-builtin versions of shell builtins on the standard PATH).

Beyond that, you might want to run one of the resulting commands manually to verify that it is working correctly.

share|improve this answer
    
Oh, apparently I have to set a parameter, -o, to specify the output file, otherwise it just runs without saving the changes. So... my bad on not seeing that in the documenation. However, how do I get the find command to attach the right input file to the parameter? The command itself needs to be java -jar htmlcompressor.jar -o output.html input.html. I want the input and output to be the same, thus: java -jar htmlcompressor.jar -o same.html same.html. How do I get the find command to do that? –  Questioner Apr 8 '12 at 7:38
    
Will it actually work that way? (This is worth verifying; some programs, when asked to do that, will destroy their input before they have a chance to read it.) If it will, simply specifying the {} wherever it's needed will work. –  geekosaur Apr 8 '12 at 7:41
    
Yep, that works! –  Questioner Apr 8 '12 at 7:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.