Hacker News new | ask | show | jobs
by chenxiaolong 723 days ago
This should work with any arbitrary filename:

    latest=$(printf '%s\0' <glob> | sort -zrV | head -zn1)
or with long args:

    latest=$(printf '%s\0' <glob> | sort --zero-terminated --reverse --version-sort | head --zero-terminated --lines 1
1 comments

What unix is this on? Neither the mac nor gnu manpages have a -z or --zero-terminated option for head.
Yay! Glad to see zero termination flags in more places.

EDIT: The linux manpages I read were from die.net, which it looks like were from 2010, guess I'll have to avoid them in the future. I checked FreeBSD, OpenBSD, and Mac man page to make sure, and unfortunately none of them support the -z flag yet.