-
Bash scripting help/request
I have a folder with a bunch of subfolders that I want to compress invidiually using 7zip. I really have no clue how to go about it.
It should go something like so:
What is the nth's folder's name? Nth folder's name is "x". Compress "x" as "x".7z. n++. Loop.
(basically atm I can't be arsed to figure out how to do it myself yayayayay)
-
Something like
for file in `ls -p1`;
do
if [ -d "$file" ]
command for 7zip with $file as the parameter
endif
done
And then there is Death
-
I had to change a few things (fi is used instead of endif, and using ls -p made new directories with 7zip instead of just spitting out the file), but that works great. Much better than the weird crap I was trying to pull off with arrays, anyway. Thanks.
-
Quick problem:
It doesn't accept any directories that have spaces in them. Is there a workaround to this or am I just going to have to suck it up and rename my folders? (they're game titles, so I'd like to keep the spacing if possible)
edit: Nevermind, found a fix by putting "IFS=$'\n'" before the loop.
-
Hypnotising you
Contributions
- Former Administrator
- Former Cid's Knight
-
Gah, I had fixed the endif to fi while I was testing it and writing the post, but forgot to actually make the change in my post before submitting. xD
The ls -p was there because at first I wanted to test if a element in $file was a dir by checking if it ended with a "\", but the -d test made that useless, and I forgot to remove the p switch.
And then there is Death
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules