readonly0.tests 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. unset a b
  2. #
  3. readonly a=A
  4. b=B
  5. readonly b
  6. # readonly on already readonly var is harmless:
  7. readonly b a
  8. readonly | grep '^readonly [ab]='
  9. # this should work:
  10. export a b
  11. export -n a b
  12. echo Ok:$?
  13. env | grep -e^a= -e^b= # shows nothing
  14. echo
  15. # these should all fail (despite the same value being assigned)
  16. # bash does not abort even in non-interactive more (in script)
  17. # ash does, using subshell to continue
  18. true; (a=A)
  19. echo Fail:$?
  20. true; (readonly a=A)
  21. echo Fail:$?
  22. echo
  23. # in bash, assignment in export fails, but export succeeds! :)
  24. # we don't mimic that!
  25. true; (export a=Z)
  26. echo Fail:$?
  27. #env | grep '^a='
  28. #echo "^^^a is exported"
  29. export -n a # undo that bashism, if it happens
  30. ## ash: assignment errors in "a=Z CMD" lead to CMD not executed
  31. ## echo
  32. ## export b
  33. ## # this fails to both set and export a:
  34. ## a=Z env | echo grep '^[ab]='
  35. ## echo "^^^a is not exported"
  36. ## # but external command does get executed, and $? is not mangled (stays 42):
  37. ## (exit 42); a=Z env echo Visible:$?
  38. echo
  39. # ash: this fails *silently*, bug? bash says "cannot unset: readonly variable"
  40. true; unset a
  41. echo Fail:$?