On Fri, Apr 17, 2015, at 04:46 PM, Maarten de Vries wrote:
On 04/17/2015 10:34 PM, Maarten de Vries wrote:
On 04/17/2015 10:19 PM, Christian Demsar wrote:
It works on my (single) test case so far. I don't have any more time to work in this right now, but I'll test edge cases and add more comments later (feedback is welcome).
If you use this, please, please, please back up your zip file in a different directory. I haven't tested it thoroughly enough to be confident that it won't suck your files into the black hole of /dev/null.
On a side note, it does check to make sure the directory doesn't exist, so it shouldn't clobber anything. That goes for the internal zips as well.
The only cryptic thing in the $IFS env var. That's needed for newline delimiters, so I can iterate over the zip files in a directory. I'll experiment with leaving that section out.
There's probably a bash guru out there that can do this with a one-liner, but that's beyond my skills (I'm a newbie at bash, too).
You should be able to avoid fiddling with IFS by using:
shopt -s nullglob zipfiles=(*.zip)
It also has the advantage of not spawning a process to find zip files. The nullglob option is needed in case there are no zip files, otherwise (*.zip) will turn into a literal ('*.zip') instead of an empty array.
Regards, Maarten
Oh, and I forgot to mention that when you do that you ought to loop over the array as (bash is a bit weird):
for file in "${zipfiles[@]}"; do
Otherwise paths with spaces would be a problem.
Regards, Maarten
I'll try to use the globbing. That's new to me. Is there anything else you saw that was odd? This is the first non-trivial script I've written (recursion in bash!), so I'm not sure about the placement of the functions, etc. Is there a way to declare the functions like in C? I couldn't figure that out from the section on functions in Advanced Bash Scripting. -- vixsomnis