去过困惑这个一段时间,这里是一个蒸馏脚本表示问题:bash脚本继续,尽管我希望它退出较早
#start
# note that master does not exist, so this should fail, would like to exit on the next line
git branch -D master || (echo "no master branch" && exit 1);
git fetch origin &&
git checkout master &&
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" != "master" ]]; then
echo 'Aborting script because you are not on the right git branch (master).';
exit 1;
fi
echo "done"
#end
当我运行上面的脚本,我得到这个输出:
error: branch 'master' not found.
no master branch
error: Your local changes to the following files would be overwritten by checkout:
publish-to-NPM.sh
Please, commit your changes or stash them before you can switch branches.
Aborting
Aborting script because you are not on the right git branch (master).
请注意,“完成”没有得到回应,所以脚本退出第二次出口1呼叫。但为什么脚本不在第一次出口1呼叫时退出?对此感到困惑。
看起来像这样可能会回答这个问题 - http://stackoverflow.com/questions/3822621/how-to-exit-if-a-command-failed –