1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Rep Power

    Simple bash script not working

    In the following script I'm trying to have an automated task to move all the screen shots I have taken with the "Prt Scr" button from ~/Pictures to ~/Pictures/ScreenShots
    Any ideas why it's not working. I did it at first with the mv command but was told by my instructor do it with a for loop because of globbing issues.

    # This is a script to home keep my $HOME/Pictures directory from keeting clutered up
    # with screenshots by moving them into their own directory.
    ls ~/Pictures/Screenshots\ from*.png > /dev/null 2> /dev/null
    if [ ${EXITSTATUS} == 0 ]
        for ${i} in $( ls ~/Pictures/Screenshot\ from*.png )
                mv ${i} /home/garrett/Pictures/ScreenShots/
    #mv /home/garrett/Pictures/Screenshot\ from*.png /home/garrett/Pictures/ScreenShots/
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Rep Power
    Ahh, the delights of spaces in file names; they always add to the fun!
    Wht do the ls twice, once to see if there's any files to process, then once to move them? If there's none there the ls to process them will not actually do anything.
    You mix the use of ~ and the actual hard-coded directory name /home/garrett which means that if someone else should run the script it will move their files into your sub-directory.

    Do you get any error messages that suggest why it's not working?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo