Hacker News new | past | comments | ask | show | jobs | submit login

BAT files writing other BAT files was often the only way to get scripting workflows done on primordial Windows versions, but chaos typically ensued if you attempted to rewrite the file you were presently running, as it appears that cmd didn't do anything fancy like read the whole file into memory before processing it (presumably due to the draconian memory limits people laboured under back then)



This is going off of memory as I'm not at my computer. Bash does something similar. It will read and execute the script line by line so if it's modified before bash gets to that line then weird things can happen. However, functions need to be read completely so the trick is to create a main function and call it at the end of the script.


> but chaos typically ensued if you attempted to rewrite the file you were presently running, as it appears that cmd didn't do anything fancy like read the whole file into memory before processing it

Neither does bash! That’s why you should always wrap things in a function and have the entry point of the script be the end of the file.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: