I am trying to make a photo organizer with a zsh shell script. But i am having trouble creating sub directories within each main directory(based on date). Currently the script starts from a folder i created and gets one argument(the file it needs to edit, hence the first cd $1). Secondly, i do some name changing which is irrelevant for my question. Next i create a directory for each date and move the photo to the correct directory.
The issue is, i want to loop through each date folder and make 2 new sub directories(jpg and raw). But when i run the code i get an error that there is no such file or directory..
Here is my current script:
#!/bin/zsh.
cd $1
for i in *.JPG;
do
mv $i $(basename $i .JPG).jpg;
done
for i in *;
do
d=$(date -r "$i" +%d-%m-%Y)
mkdir -p "$d"
mv -- "$i" "$d/";
done
for d in *;
do
cd $d
for i in *.jpg;
do
mkdir -p "jpg"
mv -- "$i" "jpg";
done
for i in *.NEF;
do
mkdir -p "raw"
mv -- "$i" "raw";
done
done
If anyone knows where i made a mistake that would be really helpfull since i have no clue what goes wrong and there is no debugger in nano as far as i know.
Error
➜ files sh test2.sh sdcard1
test2.sh: line 16: cd: 05-03-2022: No such file or directory
mv: rename *.jpg to jpg/*.jpg: No such file or directory
mv: rename *.NEF to raw/*.NEF: No such file or directory
test2.sh: line 16: cd: 23-10-2021: No such file or directory
mv: rename *.jpg to jpg/*.jpg: No such file or directory
mv: rename *.NEF to raw/*.NEF: No such file or directory
zsh.
? Are you sure the dot at the end of the shebang is right?