I see you have already found a workaround, so I will just try to uncover what's happening:
bash
isn't reading the whole script into memory, it's doing buffered reads on it, only as much as necessary each time (presumably that's for code sharing with terminal input). Before any external commands are launched, bash
seeks to the exact position in the script and continues to read from there after the command finishes. You can see this if you edit the script file while it's running:
term1$ cat > test.sh
sleep 8
echo DONE
term1$ bash test.sh
While the sleep
is executing, change the script from another terminal:
term2$ cat > test.sh
echo HAHA
Observe how bash
becomes confused when the sleep
is complete:
test.sh: line 2: A: command not found
It remembers that the position in the input file was 8 before the sleep
, so it tries to read from there and is confronted with the last A
from the overwritten script.
Now to your case. Normally, having a file open from a dvd locks the drive and prohibits disk change. If you nevertheless manage to change the disk, that should definitely involve an umount which should then invalidate the script fd. That's clearly not happening according to your strace
output, which is a little strange. In any case, bash
won't be able to read the rest of the script.