I am writing a short script: User chooses a folder with photos and then these photos are sorted by date of modification and renamed with pattern "PhotoX.jpg", where X is is number from 1 to total number of photos. When I execute this script first time everything is fine. The problem is, that when I try to execute this script again, on the same files, then Photo11.jpg disappeas and I don't know why. Here is code:
DIRECTORY=`zenity --file-selection --title="Wybierz miejsce docelowe" --directory`
FILES=()
eval "ls -r -path $DIRECTORY/ -t > temp.txt"
COUNTER=$(wc -l < "temp.txt")
eval mapfile -t FILES < "temp.txt"
eval "cd $DIRECTORY"
COUNTER=$((COUNTER-1))
for ((i=1;i<$COUNTER;i++))
do
eval "mv ${FILES[$i-1]} Photo$i.jpg"
done
eval "cd"
eval "rm temp.txt"
In all files, exept for Photo11, i get information in terminal, that PhotoX.jpg and PhotoX.jpg are the same files.
evalso many times?eval "ls -r -path $DIRECTORY/ -t > temp.txt". See why [ Parsing ls ] is discouraged.bash -x yourscriptis your friend.eval, just try