Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Hi guys. I am writing a script that would take a mp3 file split it into 8.5mb chunks and store it in to a directory with same name as the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2004
    Posts
    85

    What am I missing in this script?


    Hi guys. I am writing a script that would take a mp3 file split it into 8.5mb chunks and store it in to a directory with same name as the source file. Here is the script, as far as I got:
    Code:
    #!/bin/bash
    
    #Set the Parameters
    file=${1//\ /\\ }
    name=${file%.mp3}
    
    #Create Directory For the Output Files
    mkdir $name
    
    #Split the File
    split -b 8300k -a1 $file $name\ [
    
    #Move Files
    find -name $name\ [* -exec mv '{}' '$name/{}].mp3' ';'
    It works fine if you do not acount for the names with spaces, but I need to account for them. I used '\ ' to comment out the spaces. But when it comes time to create a directory it messes up, same is true for the split command.

    Here is what I mean, if I give a command:
    Code:
    mkdir this\ is\ a\ test
    then evrything is just fine and it creates dir "this is a test"
    but is I do the this in the script like this:
    Code:
    file="this\ is\ a\ test"
    mkdir $file
    then the script makes 4 dirs, nameing them "this\\", "is\\", "a\\", and "test"

    Why is that?

    - Bogdan

  2. #2
    Linux Newbie
    Join Date
    Jul 2004
    Location
    WA, USA
    Posts
    102
    In the second example script you did, you used quotation marks. Try it without them.

    Robert Peaslee
    Taking a walk on the wonderful path computers have lain before me

  3. #3
    Just Joined!
    Join Date
    Jul 2004
    Posts
    85
    Nope that does not work. Any other ideas?

    - Bogdan

  4. #4
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    Try this

    Code:
    file='this is a test'
    mkdir $file
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  5. #5
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Montreal, Canada
    Posts
    1,267
    hey hey x0054
    Im glad to see your keeping yourself occupied with those scripts

    As jeremy mentionned, try creating a file with space...

    Depending on "how this works", it'll tell you if it can work or not...
    I remember back in the days, you couldn't create anything with spaces... that could be the problem

    EDIT : forgot to mention the solution to this... I never under any occasion create a filename with Spaces... simply replace the " " with "_" fairly easy to do, and very effective on any system
    \"Meditative mind\'s is like a vast ocean... whatever strikes the surface, the bottom stays calm\" - Dalai Lama
    \"Competition ultimatly comes down to one thing... a loser and a winner.\" - Ugo Deschamps

  6. #6
    Linux Guru kkubasik's Avatar
    Join Date
    Mar 2004
    Location
    Lat: 39:03:51N Lon: 77:14:37W
    Posts
    2,396
    If you want to use spaces, alot of the time you need to do it regexp style with a '\' before values outside a certain range, so the string 'Hello kevin" would be "Hello\ kevin" Not sure why, but give it a try.
    Avoid the Gates of Hell. Use Linux
    A Penny for your Thoughts

    Formerly Known as qub333

  7. #7
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Montreal, Canada
    Posts
    1,267
    Quote Originally Posted by qub333
    If you want to use spaces, alot of the time you need to do it regexp style with a '\' before values outside a certain range, so the string 'Hello kevin" would be "Hello\ kevin" Not sure why, but give it a try.
    the "\" before tell the command interpreter not to take the next caracther as a "command option" like in C, to give a path, it would be something alike "c:\\blabla\\somefile.txt"
    \"Meditative mind\'s is like a vast ocean... whatever strikes the surface, the bottom stays calm\" - Dalai Lama
    \"Competition ultimatly comes down to one thing... a loser and a winner.\" - Ugo Deschamps

  8. #8
    Linux Newbie
    Join Date
    Jul 2004
    Location
    WA, USA
    Posts
    102
    Commonly called escaping characters.

    I was looking around online, and never really realized how powerful bash is. I think I need to get my hands a bit more dirty than just using it to run simple commands...

    Robert Peaslee
    Taking a walk on the wonderful path computers have lain before me

  9. #9
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    http://www.oreilly.com/catalog/bash2/?CMP=IL7015

    You'll be happy you got it!
    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  10. #10
    Linux Guru kkubasik's Avatar
    Join Date
    Mar 2004
    Location
    Lat: 39:03:51N Lon: 77:14:37W
    Posts
    2,396
    jeremy-did we review that at some point here? or was it one of those we talked about for a while but never did, or did we do something else about bash.....
    Avoid the Gates of Hell. Use Linux
    A Penny for your Thoughts

    Formerly Known as qub333

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •