I'm attempting to move all the files in a series of directories into a subdirectory of their respective folder. There are many folders that need to have this happen to, so I've put it in a loop. For the sake of the example, I've reduced the number.
read var1
case ${var1} in a) sub="sub_directory1";; b) sub="sub_directory2";; esac
for ((i=1; i<=5; i++)); do
case ${i} in
1) t=a;; 2) t=b;; 3) t=c;; 4) t=d;; 5) t=d;;
esac
mv "${location[files]}${t}/*.*" "${location[files]${t}/${sub}
done
${location[files]}
, ${t}
, and ${sub}
are all directories so that the structure looks similar to this:
/files/a/file1.txt
/files/a/file2.txt
/files/a/sub_directory1
/files/a/sub_directory2
/files/b/file33.txt.3824
/files/b/file52f.log.345
/files/b/sub_directory1
/files/b/sub_directory2
so on and so forth. The idea is that files in /files/a/
will be moved to files/a/sub_directory1
.
When I run this in the script, it appears to expand the variables properly, but evidently not the correct way for mv. I get
mv: cannot rename files/a/*.* /files/a/sub_directory1/*.*:
No such file or direbctory
When I do that same command manually:
mv /files/a/*.* /files/a/sub_directory1
it works as intended.
Is it that the wildcards are being treated literally?