I'm wondering how did you dertermine the end of a script/file? I'm especially interested for old Unix versions (like V6).
Is there a '\0' after the last written character?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Userland programs under even older Unixes did not see "pad" bytes at the end of a file. I know that MS-DOS or CP/M would fill disk blocks with Ctrl-Z characters, so not only did a file reading algorithm have to check for end-of-disk-blocks, it also had to check for padding bytes.
Unixes never did that sort of thing. Programs read bytes until the end-of-file condition happens, which for the
read(2) system call means returning 0. Unfortuately a long-running system call can be interrupted, which causes
read() to return the error code (-1), and the global symbol
errno evaluates to EINTR, so Unixes also traditioally introduce some goofiness into reading certain devices.
There's also a file system aspect to this all: Unix filesystems would put data into disk blocks, and keep a file-size-in-bytes value in the inode. Some other OSes only kept file size in blocks. If data was smaller than a block, the problem bubbled up into userland, with pad bytes or other nonsense.
Not necessarily. The shell interpreter reads the file with the script using some (more or less complex) syscall wrapper (e.g.
fread()) and that will signal the end-of-file condition when it reaches the last byte of the file (which doesn't need to be zero).