3 ms·
I've been a Linux coder and user forever, and I didn't know that bash "reloads" a script while running if the file is modified. Good to learn before I also dele
by l33tman 5y ago
I've been a Linux coder and user forever, and I didn't know that bash "reloads" a script while running if the file is modified. Good to learn before I also delete a whole filesystem due to this! :)
- deleted 5y ago[deleted]
- tyingq 5y agoIs that what happened? I can't reproduce that by changing a bash script that's running a while [ 1 ] loop. Is it maybe that they were editing or copying the file and a cron job kicked off?
- marcan_42 5y agoThat's because it's a loop, so it's already read. Try appending a line to a running script instead.
- tyingq 5y agoAh, yep. This does work, and prints out both "one" and "two": printf "echo one\nsleep 3\n" > s1;(bash s1 &);sleep 1 && printf "echo two\n" >> s1 That's interesting. And changing the "sleep 1" to "sleep 4" make it only output "one".
- deleted 5y ago[deleted]