Sunday, April 22, 2012

BASH directory recursion, scope and local variables

How quaint, I am using a bash shell script to do backups of my data, very similar to time machine if anyone is familiar.  Not sure why shell, at this point I can count on so many other things to be included, but I chose shell.  My directory recursion was failing after a few loops and I could not figure out why, until I found out that bash does not do lexical scope very well, and local variables need to be declared as local explicitly.  This way when a recursive invocation exits it's assignments will not live on.

No comments:

Post a Comment