https://ideone.com/iw2pSv
#!/usr/bin/env bashdeclare -r r r=2 || exit 2 echo 'still there with $?='$?', after: r=2 || exit 2' if ! r='hello'; then exit; fi echo "still there with \$?=$?, after: if ! r='hello'; then exit; fi" typeset -p r
Output:
still there with $?=1, after: r=2 || exit 2 still there with $?=1, after: if ! r='hello'; then exit; fi declare -r r
-- Léa Gris