bareutils
bareutils copied to clipboard
Fix negative args and files without ending \n
To support negative arguments to -n like some other head implementations, mapfile the whole file to get the total length and if the arg is negative, make the lines printed the arg added to the file length. Don't remove trailing newlines with mapfile, and don't add them with printf, to avoid printing an extra newline when a file doesn't end with one.