Bash: how to print filename of nth file in folder
1 answer
Very close, but you need to make a globe to collect the list into your array, instead of having a list with only one element (parent directory):
files=( /path/to/files/* )
echo "${files[772]}"
If you want to represent your filename in a way that is human-readable non-printable characters echo
is the wrong tool. Consider instead:
printf '%q\n' "${files[772]}"
If your path comes from a variable, be sure to include its extension, but not the globe symbol:
files=( "$dir"/* )
+6
source to share