4 ms·
I'm glad someone finally wrote about this issue. I have also stumbled upon this a few years ago, but I blamed myself (for using an editor that saves in place),
by ciprian_craciun 6y ago
I'm glad someone finally wrote about this issue.
I have also stumbled upon this a few years ago, but I blamed myself (for using an editor that saves in place), and just applied the following "workaround" when needed: wrap the whole script in a function, and as the last line of the script just call it with `_main "${@}"`.
- Pawamoy 6y agoTo expand on this, yes, you can force Bash to read more lines and keep them in memory before executing them by wrapping them in blocks. These blocks can be (), {}, functions, and maybe other structures. In addition to this, you can make sure no appended code is ever executed by explicitly running "exit" at the end of your block. I actually used this trick in a self git-updating script (the updated version could contain more lines at the end).