Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: ignore exit code, but retain output redirect

Tags:

bash

diff

I have a script whose last line is:

git diff --no-index -- ./a.json ./b.json > ./a-b.diff

diff returns an exit code of 1 when the files differ, which causes my script to report an error.

How can I ignore the exit code from diff, but retain the output redirect of the content to the diff file?

like image 618
grenade Avatar asked Jul 25 '16 22:07

grenade


1 Answers

Try:

git diff --no-index -- ./a.json ./b.json > ./a-b.diff || true

Or :

git diff --no-index -- ./a.json ./b.json > ./a-b.diff || :

Or, as long as you aren't using bash -e:

git diff --no-index -- ./a.json ./b.json > ./a-b.diff
true

Basically, you can use any command after the diff that you know will produce a zero (success) exit code.

like image 106
John1024 Avatar answered Sep 20 '22 14:09

John1024