|
|
|
|
|
by prussian
1629 days ago
|
|
>So, how could this (IMO) bad behaviour be fixed? By reading in the whole file at once.
Bash does not mmap shared the script it is parsing. You can see this behavior with strace -e read,lseek bash << EOF
echo 1
echo 2
EOF
bash will read(), do its multi-step expansion-parsing thing and then lseek back so the next read starts on the next input it needs to handle. This is why the problems described in the story can happen.The other way to fix this is to simply use editors that will just make a new file and move over that file on the target on save. I believe vim or neovim does this by default, but things like, ed or vi do not. Emacs will do something similar on first save if you did not (setq backup-by-copying t) but any write after will still be done in-place. I tested this trivially without reviewing the emacs source simply doing the following and you can to with $EDITOR of choice: !#/usr/bin/env bash
echo test
sleep 10
# evil command below, uncomment me and save
# echo test2
while running sleep, if changing the script causes things to happen, your editor may cause the problem described. |
|