Shell Script driving me nuts with MV command

Discussion in 'macOS' started by snizneth, Mar 5, 2010.

  1. snizneth macrumors newbie

    Joined:
    Mar 5, 2010
    #1
    Hi All,

    I'll be the first to admit it, I'm bad with scripts, but I'm trying to figure this script out and have hit a dead end.

    There is a large list of MV commands to move a specific file into a folder, but the script isn't working when ran all together. But strangely, it will work when i enter it line by line into terminal. Anyone know what I'm doing wrong?

    Much appreciated.

    #! /bin/sh


    mkdir design02a
    mkdir design05a
    mkdir design06a
    mkdir design09a
    mkdir design09b
    mkdir design12a

    mv 16033.mov design02a/01_16033.mov
    mv 09834.mov design05a/01_09834.mov
    mv 07144.mov design05a/02_07144.mov
    mv 02028.mov design05a/03_02028.mov
    mv 12049.mov design05a/04_12049.mov
    mv 16007.mov design05a/05_16007.mov
    mv 13096.mov design06a/01_13096.mov
    mv 15959.mov design06a/02_15959.mov
    mv 12877.mov design06a/03_12877.mov
    mv 04591.mov design06a/04_04591.mov
    mv 12559.mov design06a/05_12559.mov
    mv 04103.mov design06a/06_04103.mov
    mv 06824.mov design06a/07_06824.mov
    mv 13184.mov design06a/08_13184.mov
    mv 12248.mov design06a/09_12248.mov
    mv 11468.mov design09a/01_11468.mov
    mv 12637.mov design09a/02_12637.mov
    mv 09430.mov design09a/03_09430.mov
    mv 07465.mov design09a/04_07465.mov
    mv 12640.mov design09a/05_12640.mov
    mv 09425.mov design09a/06_09425.mov
    mv 04577.mov design09a/07_04577.mov
    mv 09255.mov design09a/08_09255.mov
    mv 05075.mov design09a/09_05075.mov
    mv 01844.mov design09a/10_01844.mov
    mv 12656.mov design09a/11_12656.mov
    mv 14554.mov design09a/12_14554.mov
    mv 13453.mov design09a/13_13453.mov
    mv 07187.mov design09a/14_07187.mov
    mv 13256.mov design09a/15_13256.mov
    mv 08650.mov design09a/16_08650.mov
    mv 13970.mov design09a/17_13970.mov
    mv 08261.mov design09a/18_08261.mov
    mv 04578.mov design09a/19_04578.mov
    mv 05715.mov design09a/20_05715.mov
    mv 13456.mov design09a/21_13456.mov
    mv 04562.mov design09a/22_04562.mov
    mv 12660.mov design09a/23_12660.mov
    mv 14789.mov design09a/24_14789.mov
    mv 13461.mov design09a/25_13461.mov
    mv 12662.mov design09a/26_12662.mov
    mv 05805.mov design09a/27_05805.mov
    mv 08641.mov design09a/28_08641.mov
    mv 03608.mov design09a/29_03608.mov
    mv 05076.mov design09a/30_05076.mov
    mv 13458.mov design09a/31_13458.mov
    mv 07190.mov design09a/32_07190.mov
    mv 04580.mov design09a/33_04580.mov
    mv 04906.mov design09a/34_04906.mov
    mv 04576.mov design09a/35_04576.mov
    mv 12666.mov design09a/36_12666.mov
    mv 07331.mov design09a/37_07331.mov
    mv 11255.mov design09a/38_11255.mov
    mv 10076.mov design09a/39_10076.mov
    mv 13736.mov design09a/40_13736.mov
    mv 07030.mov design09a/41_07030.mov
    mv 13467.mov design09a/42_13467.mov
    mv 04908.mov design09a/43_04908.mov
    mv 06806.mov design09a/44_06806.mov
    mv 13984.mov design09a/45_13984.mov
    mv 06111.mov design09a/46_06111.mov
    mv 04671.mov design09a/47_04671.mov
    mv 13469.mov design09a/48_13469.mov
    mv 08286.mov design09a/49_08286.mov
    mv 04575.mov design09a/50_04575.mov
    mv 13377.mov design09a/51_13377.mov
    mv 04570.mov design09a/52_04570.mov
    mv 04579.mov design09a/53_04579.mov
    mv 13473.mov design09a/54_13473.mov
    mv 11622.mov design09a/55_11622.mov
    mv 07193.mov design09a/56_07193.mov
    mv 04569.mov design09a/57_04569.mov
    mv 10278.mov design09a/58_10278.mov
    mv 13381.mov design09a/59_13381.mov
    mv 10494.mov design09a/60_10494.mov
    mv 02569.mov design09a/61_02569.mov
    mv 06126.mov design09a/62_06126.mov
    mv 08635.mov design09b/01_08635.mov
    mv 04231.mov design09b/02_04231.mov
    mv 16013.mov design09b/03_16013.mov
    mv 10378.mov design09b/04_10378.mov
    mv 13442.mov design09b/05_13442.mov
    mv 04229.mov design09b/06_04229.mov
    mv 13450.mov design09b/07_13450.mov
    mv 04573.mov design09b/08_04573.mov
    mv 12631.mov design09b/09_12631.mov
    mv 16012.mov design09b/10_16012.mov
    mv 02908.mov design09b/11_02908.mov
    mv 13452.mov design09b/12_13452.mov
    mv 08739.mov design09b/13_08739.mov
    mv 07293.mov design09b/14_07293.mov
    mv 06113.mov design09b/15_06113.mov
    mv 12634.mov design09b/16_12634.mov
    mv 09362.mov design09b/17_09362.mov
    mv 16009.mov design09b/18_16009.mov
    mv 14868.mov design12a/01_14868.mov​
     
  2. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
  3. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #3
    I've never had to put semicolons there, but that may be because he's declaring the shell as sh and I specify bash.

    Also, your mv commands are specifying relative folders, so you need to make sure you are in the directory where the movies currently reside and execute the script with its full path:

    Code:
    cd /path/to/movies
    /path/to/script/script.sh
    
     
  4. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #4
    I was just throwing that out there, since it does look okay. It would've been nice if he said what goes wrong (i.e., does it past the first line, etc.).

    Yeah, that's probably the problem.
     
  5. soup4you2 macrumors regular

    Joined:
    Apr 12, 2007
    #5
    try

    mv ./16033.mov ./design02a/01_16033.mov

    if that doesn't work try changing the shebang to bash.
     
  6. snizneth thread starter macrumors newbie

    Joined:
    Mar 5, 2010
    #6
    Hi Aggie, thanks for the quick reply. Tried adding the semicolon and the script will only run the first line of the MV commands. All the rest I get a "MV Command not found 0" error. Yet when I enter it line by line it still works...

    Thanks again.
     
  7. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #7
    MV is not a command; mv is. If you can upload your script as an attachment and any errors from Terminal, that would help.

    EDIT: FYI, I took your commands in your first post, created zero byte files with those filenames, and then executed and it ran fine.
     
  8. soup4you2 macrumors regular

    Joined:
    Apr 12, 2007
    #8
    Just out of curiosity how are you executing your script?
     
  9. snizneth thread starter macrumors newbie

    Joined:
    Mar 5, 2010
    #9
    We're executing through Terminal
     
  10. soup4you2 macrumors regular

    Joined:
    Apr 12, 2007
    #10
    I realized that..

    are you executing it as

    ./script.sh

    sh script.sh

    bash script.sh

    /home/scripts/script.sh

    etc..etc...
     
  11. snizneth thread starter macrumors newbie

    Joined:
    Mar 5, 2010
    #11
    With or without semicolons?
     
  12. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #12
    I grant that I'm no bash expert but I don't think you should need semicolons.
     
  13. soup4you2 macrumors regular

    Joined:
    Apr 12, 2007
    #13
    Correct. the use of a semi color is to state 'after this command move onto the next' there's no true/false with semicolons. (&& / ||)

    (ie. echo "1"; echo "2"; echo "woot" )

    Some languages like perl do require the use of a semicolon after each statement. but sh/bash do not except for certain special built-in functions.
     
  14. snizneth thread starter macrumors newbie

    Joined:
    Mar 5, 2010
    #14
    We're executing it as ./script.sh
     
  15. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #15
    Two ideas:
    1. For shebang line (1st line): #!/bin/bash
    2. Where are you editing the file? Make sure the editor is using Unix line endings.
     
  16. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #16
    More ideas:

    Add this MV=/bin/mv;

    Then change mv to $MV in the rest of the script.

    And you might need a PATH environment variable to make sure your mdir is puttting the directories where you think they are and that your mv is copying them to where you think you're copying them.
     
  17. snizneth thread starter macrumors newbie

    Joined:
    Mar 5, 2010
    #17
    Hi Guys,

    We figured it out. Something about having a .mov at the end of the file name. Once we removed it, it worked... go figure.

    It's not extremely important, but does anyone know why this would be? or how we could use the .mov extension in the future? Once it copies the file, it no longer has a visible .mov extension.

    Thanks for all your help. Much appreciated.

    Seth
     
  18. soup4you2 macrumors regular

    Joined:
    Apr 12, 2007
    #18
    put the path/filemane inside quotes

    mv '04103.mov' 'design06a/06_04103.mov'
     
  19. belvdr macrumors 603

    Joined:
    Aug 15, 2005
    #19
    It sounds to me like Finder displayed them as .mov files, but the extension didn't exist on the file itself. cp or mv will not remove/add extensions unless you tell it to.

    That should only be needed if there are spaces in the filename.
     

Share This Page