fork download
  1. #!/usr/bin/env bash
  2.  
  3. declare -r r
  4.  
  5. r=2 || exit 2
  6.  
  7. echo 'still there with $?='$?', after: r=2 || exit 2'
  8.  
  9. if ! r='hello'; then exit; fi
  10.  
  11. echo "still there with \$?=$?, after: if ! r='hello'; then exit; fi"
  12.  
  13. typeset -p r
Success #stdin #stdout #stderr 0s 4892KB
stdin
Standard input is empty
stdout
still there with $?=1, after: r=2 || exit 2
still there with $?=1, after: if ! r='hello'; then exit; fi
declare -r r
stderr
./prog.sh: line 5: r: readonly variable
./prog.sh: line 9: r: readonly variable