The GNU-specific head -n-1 syntax causes errors on macOS/BSD systems. Replaced with sed '$d' which is POSIX-compatible and achieves the same result of removing the last line.