by tremon · 2y ago · 0 comments
latest="$(ls -1 $pattern | sort --reverse --version-sort | head -1)"
Anyone got a better solution?In that case, how about:
IFS='' read -d '' latest < <(find $pattern -prune -print0 | sort -z --reverse --version-sort) 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 1EDIT: 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.