I refuse to parse ls output, because it is unstable.
First attempt failed with read and find:
read VARIABLE < $(find ./ -type f -name "PATTERN" | sort -r)
But it results ambiguous redirect.
Second attempt failed: it saved /boot file, no idea why, I was not in /:
find ./ -type f -name "PATTERN" | sort -r | read VARIABLE
Third attempt failed: use a subshell:
{ read VARIABLE; } < $(find ./ -type f -name "PATTERN" | sort -r)
No changes.
Finally I achieved, what I wanted:
variable=$(find ./ -type f | sort -r | head -1)
But the solution does not satisfy me, because using head to extract first line seems ugly.
In addition it is highly probable that I would need only second line (what I would get by head -2 | tail -1, I know)
I wonder whether it is possible to use some variation of this:
{ read line1 ; read line2; } < $(find ./ -type f -name "PATTERN" | sort -r)