I write a script that iterates over a set of zip files, extracts them and moves only files that match a specific filename pattern to another folder.
The script:
#!/bin/bash
ARCHIVE_FILEMASK="????-??-??_E_MDT_0_0.7z"
FILEMASK="?????????_?????_A_?_????????????????-?????????"
extractDir=/path/to/dir
dest=/path/to/dest
for f in ${ARCHIVE_FILEMASK}
do
7z e -aoa -o"${extractDir}" "$f"
if [ $? != 0 ]
then
mv "${extractDir}/${FILEMASK}".xml "$dest"
fi
done
When the script is executed an error occurs:
mv: cannot stat `/path/to/dir/?????????_?????_A_?_????????????????-?????????.xml': No such file or directory
I've already tried turning on nullglob and extglob but it didn't help. If I execute the command directly from the shell, it runs just fine. The answers from other posts with similar problems also didn't help.
edit:
After Paweł Rumian mentioned possible problems with spaces in directory names, I tried AVJ's tip and added set +x before the mv command.
The result is:
+ mv '/path/to/dir/?????????_?????_A_?_????????????????-?????????.xml' /path/to/dest
So obviously I have to get rid of the single quotes now. Any idea how?
#!/bin/bash