It seems that somehow my knowledge of bash is not really great as after so many years I discover something weird:
#!/bin/bash
set -e
# so we expect to exit with error code on first failure
false || true
echo "ok, expected to reach this place"
false && true
echo "why am I here?"
Now, I am asking this because I found this why trying to use the gerrit cherry pick code snippet inside a bash script, and to my surprise it failed to exit when the first command failed.
set -e
git fetch https://review.gerrithub.io/xxx/123 refs/changes/01/123456/666 && git cherry-pick FETCH_HEAD
The code above is provided by gerrit as so you can easily copy/paste it and the &&
is supposed to prevent running the 2nd command when the first fais. Still when this code is put inside a bash script using set -e
, it fails to return an exit code and your script continues instead of stopping.
Obviously I could replace the &&
with a ;
or new-line but that's not the point. Isn't it possible to make this piece of code work the same in both cases?