Reputation: 12973
#/bin/bash
PATH_GSUTIL=""
[ -f "$PATH_GSUTIL"/gsutil ] || (echo "$PATH_GSUTIL does not contain 'gsutil'" && exit)
echo a
I would expect it to quit on exit
. How come it goes on and executes the next line?
Upvotes: 0
Views: 62
Reputation: 66283
Building upon unwind's answer: ()
creates a subshell which then executes the exit
. You can use the {}
(with some more whitespace required around the {
and }
). That will do the job in your case, because the exit
will then be executed by the outer shell.
Upvotes: 1
Reputation: 400079
The ()
command grouping operator creates a sub-shell, which is what you're exiting from.
Upvotes: 2