This is because (..)
starts a subshell. Anything process related you do inside it will only affect that subshell.
Instead, use {..}
grouping:
#!/bin/sh
test || {
echo "Test failed, exit!"
exit 1
}
echo "Test succeeded!"
The (..)
behavior is very useful when you actually do want to contain effects, such as
for dir in */
do
( cd "$dir" && make ) # This 'cd' will be contained inside the ()
done
which prevents you from having to keep track of whether you were able to cd in, and therefore whether or not you have to cd ..
to make it back to where you were.