Is there a way, using POSIX shell and utilities, to reliably test if two files are on the same file system? It seems like a basic feature that the shell should have access to, so I'd like to add it to the modernish shell library.
The only POSIX command I've found so far that identifies the file system that a file is on, is 'df -P', so I've experimented with parsing its output. Given two file arguments, it normally outputs their file system names in the first field of the second and third lines. The fields are separated by one or more spaces. Unfortunately, on the Mac, some of the file system names contain spaces (on my system: "map -hosts" and "map auto_home"). POSIX doesn't seem to prohibit this: file system names are considered implementation-defined[*]. Given that there is a fixed number of fields, it would be possible to cope with this if no other fields can contain spaces, but the last field is a directory name that may also contain spaces -- or even newlines. So the output of 'df -P' is unparseable. GNU stat (or gstat) makes this trivial: 'stat --file-system --format=%i /file/one /file/two' provides two hexadecimal file system identifiers to compare. But GNU stat is not standard and nowhere near ubiquitous. BSD 'stat' does not have any such feature. Is there anything else POSIX or de-facto standard that could be (ab)used to determine if two files are on the same file system? Thanks, - M. [*] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/df.html#tag_20_33_10
