I need help getting over this bump on how nested for loops work in shell. Say i was comparing files in a directory in any other language my for loop would look like so
for(int i=0;to then end; i++)
for(int y = i+1; to the end; y++)
I can't seem to understand how i can translate that into shell,
where I want the first for loop to start at the first file and the second for loop to start at the second.
so
for f in $aDirectory; do
for f in $aDiredtory
confuses me. Since f in both loops would start at the same file. Any recommendations?
i guess my question is how would i do that with nested for-do loops in shell when iterating through a directory start at two different indexes?
for aFile in aDirectory;do
for theNextFile in aDirectory; do
cmp aFile theNextfile
when i run the 'real' code it returns the same file since both for loops start at the same point. How would i offset the second for loop so it starts out on the next file?
Your approach is correct.
The top loop will get one file at a time.
The inner loop, will compare the above first file with all the files in the directory.
The only hitch is, in the inner loop, when comparing, every file will be comparing to itself once. You can take care of this by comparing the file name in an if-else condition.
Lets say you have files A, B, C, D
What you will get is: