3 ms·
What you describe is also interesting behaviour but it is different from the effect seen in bash. For bash it works rougly like this (discounting the shebang t
by weinzierl 7y ago
What you describe is also interesting behaviour but it is different from the effect seen in bash.
For bash it works rougly like this (discounting the shebang to keep things simple):
1. bash reads first line and remembers the byte offset where to continue next. In this case at the octothorpe at byte position 10 (assuming UNIX line endings).
2. bash executes first line
3. while bash is still busy with the first line someone removes a character before position 10
4. Bash reads what it assumes to be the next line at byte position 10, which is now where the 'r' is.
5. bash executes 'rm -rf --no-preserve-root'
EDIT: The observed behaviour for a DOS/Windows batch file is indeed the same. I assumed that the trick would not work because supposedly Windows reads the whole file again after every command, but apparently it does not remember the line it was executing but also a byte offset
echo start
pause
echo stop
Removing the last character from the first line while the script is paused results in
Bad command or filename - "cho".