I am not looking to break new ground, just simply document some of the things that I found to be useful in everyday work. Sometimes I spend a considerable amount of time to find a solution for a problem that seemed silly and simple. I hope that some of my posts will save you some time.
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.
Labels:
bash,
directory recursion,
unix,
unix scripting
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment