The POSIX specification does not seem to say anything about what happens when one line provided to the sort
program is the prefix of another.
But I find that my copy (GNU coreutils 8.4) gives precedence to the prefix:
$ echo -e 'foo\nfoobar' | sort
foo
foobar
$ echo -e 'foobar\nfoo' | sort
foo
foobar
sort
?Sort order is defined by the current locale, which is all the POSIX spec has to say. Your current locale (and most locales, I suspect) will consider a prefix to be lexicographically smaller than the string itself.