readonly0.tests 882 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. true; a=A
  18. echo Fail:$?
  19. true; readonly a=A
  20. echo Fail:$?
  21. echo
  22. # in bash, assignment in export fails, but export succeeds! :)
  23. # we don't mimic that!
  24. true; export a=Z
  25. echo Fail:$?
  26. #env | grep '^a='
  27. #echo "^^^a is exported"
  28. export -n a # undo that bashism, if it happens
  29. echo
  30. export b
  31. # this fails to both set and export a:
  32. a=Z env | grep '^[ab]='
  33. echo "^^^a is not exported"
  34. # but external command does get executed, and $? is not mangled (stays 42):
  35. (exit 42); a=Z env echo Visible:$?
  36. echo
  37. true; unset a
  38. echo Fail:$?