I was trying to debug something and stumbled into some weird bash behavior. I assume it's just a caveat I'm unaware of, but I've looked around in the docs for a bit and haven't found any explanations.
It seems like there's some small distinction/bug between simple commands, and command lists. (context: https://www.gnu.org/software/bash/manual/html_node/Shell-Commands.html)
Basically:
- set a variable readonly
- try to modify the variable
- try to do something else
- something else runs if
- you do it all in a single simple command
- you do it at the root of the document with newlines
- something else is skipped if it is in any kind of command list
- something else runs if
There's an output file with the result from bash, (bash-based) sh, and osh. I see the behavior in both 3.2 and modern bash.