简体   繁体   中英

How can I prevent the patch command from exiting a bash shell?

I have a bash script that looks like this:

#!/bin/bash

set -e

function patchStuff {
  patch --unified --input=<...>.patch --strip=0 --forward --reject-file=<...>.patch.rej --verbose --dry-run
}

function doMoreThings {}

patchStuff
doMoreThings # never reached

exit 0

It completes/exits right after the patch command completes. How can I prevent, stop or ignore that. I played with running the command in a subshell, but that didn't do the trick.

bash -c "patch ..."

If you don't want a particular command to trigger the exit that set -e specifies, you can negate it.

! patch ...

POSIX and the bash manual specify that set -e doesn't apply to a command that has been negated with ! .

Instead of negating you also can always return 0 exit status:

patch ... ||:

or

patch ... || true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM