#!/usr/bin/env bash

declare -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