/bin/bash if statement pattern search, end of pattern special character?
Hi,
I have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.
Here's how I try to do it:
- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email
The problem:
- search in the array the files that have a specific file extension
here's the code so far:
-------------------------------------------------------------------------
#!/bin/bash
i=0
j=0
k=0
match='.vmx'
match2='.vmxf'
cd /path/to/the/original/files
for f in *; do
files[i++]=${f}
if [[ "$f" =~ .vmdk ]];
then
# echo $f;
vmdktocompare[j++]=${f}
fi
done
for f in *; do
files[i++]=${f}
# if [[ "$f" =~ $match ]];
if [[ "$f" =~ ".vmx" && "$f" != $match2 ]];
then
vmxtocompare[k++]=${f}
fi
done
echo ${vmdktocompare[*]}
echo ${vmxtocompare[*]}
exit 0
-------------------------------------------------------------------------
The output:
# sudo ./listdir.sh
test2.vmdk test.vmdk
test.vmx test.vmxf
As you can see the search pattern ".vmx" is not exactly respected by the system, as for it ".vmx" and ".vmxf" are both matching the search pattern. Which is entirely true.
Does anybody know how to tell the system: search for this: ".vmxAND_STOP_HERE", don't look for ".vmxXXXXXXXXXXXXXXX".
Is there a special character that can tell the system that the pattern stops after ".vmx"? I googled for two days but no luck.
I tought this line should do the trick:
if [[ "$f" =~ ".vmx" && "$f" != $match2 ]];
but apparently, the boolean AND is ignored.
Thanks
|