Problem with a mv script

I am having a problem with a mv script.

  1. I create a Test folder:

    mkdir Test
    
  2. In this folder I create subfolders:

    mkdir -p Pics20{18..23}/{01..12}
    
  3. In the Test folder I create many files:

    touch IMG20{18..23}{01..12}{01..30}{01..10}.jpg
    
  4. Now I need to move all these IMG files to the respective subfolders, so I wrote a script:

    for i in 20{18..23}
    do
      for j in {01..12}
      do
        mv IMG20$i$J* Pics20$i/$j
      done
    done
    

    But I keep getting an error:

    cannot stat 'IMG202018j*': No such file or directory
    

What is wrong with my script?


I had to create a test directory with 'your content'. That way I made a working one-liner,

for i in 20{18..23}; do for j in {01..12}; do mv "IMG$i$j"* "Pics$i/$j"; done; done

You had to replace J by j and add semicolons to separate statements. It was also important to get the file names and directory names to match (watch how to add '20')

It is also good practice to double-quote expressions with variables.