Results 1 to 6 of 6

Thread: Bash scripting help/request

  1. #1
    Got obliterated Recognized Member Shoeberto's Avatar
    Join Date
    Jun 2000
    Location
    THE OC BABY
    Posts
    12,020
    Blog Entries
    1
    Contributions
    • Former Cid's Knight

    Default 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)


  2. #2
    Prinny God Recognized Member Endless's Avatar
    Join Date
    Aug 2000
    Location
    Prinny Moon
    Posts
    2,641
    Contributions
    • Former Cid's Knight

    Default

    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

  3. #3
    Got obliterated Recognized Member Shoeberto's Avatar
    Join Date
    Jun 2000
    Location
    THE OC BABY
    Posts
    12,020
    Blog Entries
    1
    Contributions
    • Former Cid's Knight

    Default

    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.


  4. #4
    Got obliterated Recognized Member Shoeberto's Avatar
    Join Date
    Jun 2000
    Location
    THE OC BABY
    Posts
    12,020
    Blog Entries
    1
    Contributions
    • Former Cid's Knight

    Default

    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.


  5. #5
    Hypnotising you crono_logical's Avatar
    Join Date
    May 2001
    Location
    Back in Time
    Posts
    9,313
    Contributions
    • Former Administrator
    • Former Cid's Knight

    Default

    I shall remember that - I've had problems with scripting and filenames with spaces in before too
    Problems playing downloaded videos? Try CCCP


  6. #6
    Prinny God Recognized Member Endless's Avatar
    Join Date
    Aug 2000
    Location
    Prinny Moon
    Posts
    2,641
    Contributions
    • Former Cid's Knight

    Default

    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
  •