I would like to do a loop and inside the loop get the previous and the next item.
Currently, I am using the following loop:
for file in $dir;do
[...do some things...]
done
Can I do things like in C, for example, file[i-1]/file[i+1] to get the previous and the next item? Is there any simple method to do this?
In the first iteration, the index -1 will print the last element and in the last iteration, the index max+1 will not print anything.