0

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.

#!/bin/bash

# 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
EXITSTATUS=${?}

if [ ${EXITSTATUS} == 0 ]
then
    for ${i} in ls ~/Pictures/Screenshot\ from*.png
        do
            mv ${i} /home/garrett/Pictures/ScreenShots/
        done
fi

#mv /home/garrett/Pictures/Screenshot\ from*.png /home/garrett/Pictures/ScreenShots/
#END#
2
Contributors
1
Reply
12
Views
5 Years
Discussion Span
Last Post by mike_2000_17
0

you shouldn't use the ${} evaluation for the variable in the for loop, at least, I never do. And the for loop will recognize the globbing too, so you shouldn't use the ls command. Try this:

for i in ~/Pictures/Screenshot\ from*.png;
    do
        mv ${i} /home/garrett/Pictures/ScreenShots/
    done
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.