View Single Post
Old September 17th, 2013, 08:21 PM   #937 (permalink)
palmtree5
Sunny Vacation Supporter!
 
palmtree5's Avatar
 
Join Date: May 2012
Location: USA
Gender: Male
Posts: 3,373
 
Device(s): HTC One SV, Samsung Galaxy Prevail (retired), Nexus 7 (Gen 1)
Carrier: Boost Mobile

Thanks: 2,245
Thanked 1,899 Times in 999 Posts
Default

Quote:
Originally Posted by MoodyBlues View Post
Okay, here's my script:

[high]
#!/bin/bash
SUBDIR=$1
SAVEIFS=$IFS

IFS=$(echo -en "\n\b")
cd $SUBDIR

for SUBDIR2 in `ls -d1 */`
do ZIPFILE=$(basename "$SUBDIR2")
zip -r $ZIPFILE/$ZIPFILE.zip $SUBDIR2
done

# cleanup
IFS=$SAVEIFS
[/high]

As always, this can be tweaked as needed/desired. Right now, it's taking you to the directory whose name you enter at runtime, then it's doing its thing as far as locating subdirectories and zipping their contents. It's creating the zipped files in each subdirectory; of course that can be changed to wherever you'd prefer.

And thanks to EM for the $IFS idea.
Quote:
Originally Posted by EarlyMon View Post
Don't have to pump those through sed to escape any blanks in the path name?
Apparently not. What Moody posted works
__________________
Find a post helpful? Hit
See spam or something offensive? Hit
New to the site? Site Rules/Guidelines and Introductions
Not a member yet but want to join? Join here!
Want to chat with staff?Here
Want to chat with mods?Here
palmtree5 is online now  
Reply With Quote