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 a bash script that expands two archives (jar files) into two directories and then does a diff of the two folders. I want the diff to be piped into a file so I do this in the bash file.

diff -r $originalJarExtracted $assembledJarExtracted >target/$diffList

While this works it also stops the script and anything afterwards is not executed. How can I get diff to pipe its output into the file and for the script to keep going. I looked at the info and man pages for diff but could not get this to work. I am running the script on the mac btw.

Just for reference the scripts are on github

share|improve this question
The script will keep executing. Post the whole script (or a reduced script that exhibits the problem, if the whole script is very long). –  Gilles Jan 5 '12 at 0:00
Have you tried putting it in background &? A nice trick when debugging your scripts is to execute it like bash -x yourscript It will output the execution trace with the contents of variables to standard output/error. –  Herman Torjussen Jan 5 '12 at 0:05
add comment

1 Answer

Wild guess: your script is operating under set -e (synonym: set -o errexit), which causes the shell to exit if any commands returns a nonzero status (conventionally indicating failure). If so, it will exit if diff finds any difference, because diff returns the status 1 if it finds differences. If this is the problem, then change that line to

diff -r "$originalJarExtracted" "$assembledJarExtracted" >"target/$diffList" ||
[ $? -eq 1 ]

Then the script will only exit if diff returns a status other than 0 (no difference) or 1 (differences), i.e. only if there was an error such as a missing file.

share|improve this answer
Your wild guess was correct. If I take set -e out the script works. Adding your suggested changes however does not fix it, but at least I can run the scripts all in one now.. –  Manfred Moser Jan 5 '12 at 0:25
add comment

Your Answer


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.