@vaporeon_ probably the most recent mistakes I have made were bash-related. I made some wrong assumptions regarding scope rules for variables, resulting in situations where variables in loops had values from previous iterations of the loop that I didn't expect, causing subtle bugs that took me hours to unravel
@vaporeon_ if I declare a variable in a for loop in C, it "resets" each start of the loop
That does not happen in bash, obviously, but I wrongly assumed that it did
@vaporeon_ scope is probably the wrong word here
@wallhackio It sounds like the correct word to me...
@wallhackio @vaporeon_ scope is exactly the word fur this
@aescling @vaporeon_ this might surprise you, but I wasn't aware
@wallhackio @vaporeon_ really C is block scoped and for loops are an implicit block. you can introduce new blocks arbitrarily wherever a statement is allowed
@aescling @wallhackio Yes, you can even start a block without any for or while or function definition... Should you? No. But can you? Yes:
#include <stdio.h>
int main() {
int i = 0;
{
int i = 7;
printf("i (inner): %d\n", i);
}
printf("i (outer): %d\n", i);
return 0;
}
@wallhackio Got an example? I am Unaware of the scope rules for Bash, actually, but I'm guessing based on your comment that they're different from the scope rules for C?