I'm getting a parsing error in the 773rd file of a folder. Is it possible to print the name of the file in bash?
I've tried using this to print it but it returns a blank.
files=(/path/to/files)
echo "${files[773]}"
I'm getting a parsing error in the 773rd file of a folder. Is it possible to print the name of the file in bash?
I've tried using this to print it but it returns a blank.
files=(/path/to/files)
echo "${files[773]}"
Very close, but you need to actually do a glob to collect the list into your array, rather than having a list with only one element (the parent directory):
files=( /path/to/files/* )
echo "${files[772]}"
If you want to represent your filename in a way that represents nonprintable characters in a human-readable way, echo is the wrong tool. Instead, consider:
printf '%q\n' "${files[772]}"
If your path is coming from a variable, be sure to quote its expansion, but not the glob character:
files=( "$dir"/* )