bash: resetting of global variable?
Hi,
I the following code to search a directory recursively: Code:
declare -i COUNTER=0 Code:
counter: 0 |
Try COUNTER=$(($COUNTER + 1)).
Wouldn't it easier just to do a ls -r $1? |
Quote:
I already tried COUNTER=$(($COUNTER + 1)). Does not work. Quote:
Yes, that would be definetly easier. But I am still new to bash and the main purpose for me at this point is educational value rather than efficiency. Besides, it is still interesting to find out where the bug is. |
This sort of thing is what "find" is for
http://mywiki.wooledge.org/UsingFind |
Quote:
|
http://mywiki.wooledge.org/BashFAQ/024
http://mywiki.wooledge.org/ParsingLs Doing it the right way is not "working around the problem" |
Quote:
the links were really helpful. I used a recursive function and not a recursive call to the same script to avoid the subshell problem. But there it was again. So this how I do it now: Code:
find $SEARCHDIR ! -type d >> $LOGPATH |
There's a way to make it not run in a subshell environment but it's not a good idea since it will require to spawn multiple processes at runtime. There could also be a limit in the number of file descriptors that can be used.
Code:
declare -i COUNTER=0 |
All times are GMT -5. The time now is 12:53 PM. |