Why does this script not reliably log the latest file?

This script fails sometimes and succeeds sometimes (a very annoying situation): #!/bin/bash set -Eeuxo pipefail test_dir=”$(mktemp -d)” touch “$test_dir/file”{001..312} latest_file=”$(find $test_dir -type f | sort -r | head -n1)” echo $latest_file When it succeeds, it logs something like this: ++ mktemp -d + test_dir=/tmp/tmp.yWelcpBYB7 + touch /tmp/tmp.yWelcpBYB7/file001 /tmp/tmp.yWelcpBYB7/file002 … /tmp/tmp.yWelcpBYB7/file312 ++ find /tmp/tmp.yWelcpBYB7 -type f…

Details