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#

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.