I have command:
bigfiles=$(find "${path}/" -printf '%s %p\n'| sort -nr | head -2 | sed 's/^[^ ]* //')
Now I want to get last item like
anotherfile=$bigfiles[1]
and it seems to be empty
How to get n-th element of results from find command ?
by using mapfile which is a bash4+ feature, might do what you wanted.
mapfile -t bigfiles < <(find "${path}/" -printf '%s %p\n'| sort -nr | head -2 | sed 's/^[^ ]* //')
anotherfile=${bigfiles[-1]}
echo "$anotherfile"
-1 is the last element/item in the array.
If you're just interested in the last item with find's output , you can probably pipe the output to tail or maybe head depending on what you're trying to do with it.
$bigfilesis not array.